Cat File with No Line Wrap

cat file with no line wrap

Note that cut accepts a filename as an argument.

This seems to work for me:

watch 'bash -c "cut -c -$COLUMNS file"'

For testing, I added a right margin:

watch 'bash -c "cut -c -$(($COLUMNS-10)) file"'

When I resized my terminal, the truncation was updated to match.

No line breaks with cat

You could try:

echo $chksitename | tr ' ' '\n'

cat without line breaks: why does tr '\n' not work?

If all your files are missing the final linefeed then you can use sed for adding it on the fly:

# with GNU sed
sed '$s/$/\n/' filnename_* > outfile

# with standard sed and bash, zsh, etc...
sed $'$s/$/\\\n/' filnename_* > outfile

# with standard sed and a POSIX shell
sed '$s/$/\
/' filnename_* > outfile

Linux command to remove word wrap for entire csv file

Assuming that the newline within fields and at the end of each record is \n because if it was \n within the fields and \r\n at the end of each record as exported by MS-Excel then this would be trivial, the following uses GNU awk for various extensions (multi-char RS, RT, FPAT and \s).

This will combine the lines:

awk -v RS='"[^"]+"' -v ORS= '{
gsub(/\n/,"",RT)
print $0 RT
}'

and this will remove leading/trailing spaces and enclose each field in quotes:

awk -v FPAT='[^,]*|"[^"]+"' -v OFS=',' '{
for (i=1;i<=NF;i++) {
gsub(/^"?\s*|\s*"?$/,"",$i)
printf "\"%s\"%s", $i, (i<NF ? OFS : ORS)
}
}'

so you could just use them together in pipe:

$ awk -v RS='"[^"]+"' -v ORS= '{gsub(/\n/,"",RT); print $0 RT}' file |
awk -v FPAT='[^,]*|"[^"]+"' -v OFS=',' '{for (i=1;i<=NF;i++) {gsub(/^"?\s*|\s*"?$/,"",$i); printf "\"%s\"%s", $i, (i<NF ? OFS : ORS)} }'
"ID","OPPORTUNITY ID","CREATED_DATE","TIR NAME","MS Rep","SRC_SSR_REP","REGION","HP PBM NAME","COMPANY NAME","COMPANY ADDRESS","COMPANY CITY","COMPANY STATE","COMPANY ZIPCODE","COMPANY AMID","COMPANY USER CONTACT NAME","COMPANY USER TITLE","COMPANY USER PHONE","COMPANY USER EMAIL","PARTNER COMPANY NAME","PARTNER REP NAME","PARTNER REP EMAIL","PARTNER LID","WHOLESALER","PURCHASEDGE AC NUMBER","USAGE PERIOD","DEAL TYPE","CLWB WORKED ON","DEAL NUMBER","NAMED TERRITORY SLED","MONO HP SHARE %","COLOR HP SHARE %","TOTAL HP TONER SHARE %","DEAL VALUE MONO","DEAL VALUE COLOR","TOTAL TONER DEAL VALUE","EST DISCOUNT VALUE","REBATE TYPE MONO","REBATE TYPE COLOR","DISCOUNT TYPE","DEAL START DATE","DEAL END DATE","DEAL EXTENDED END DATE","DEAL POSITION","ECLIPSE ID","ECLIPSE DEAL STATUS","ECLIPSE APPROVED DATE","ECLIPSE DEAL APPROVED BY","LOST REASON","USAGE FILE LOCATION","CREARTED BY","MODIFIED BY","MODIFIED DATE","FINALISATION_RECEIVED_DATE","FINALISATION_WORKED_DATE","DEAL_PROCESSED_BY","DEAL_FINALISED_BY","FUNNEL_COMMENT","AV_SENT_DATE","PL_REMAN_VALUE","PL_REMAN_SHARE","FINALISATION_DOC_PATH","TIME ELAPSING ON","APPROVAL SENT DATE","APPROVAL RECEIVED DATE","SECONDARY_WHOLESALER","PREVIOUSECLIPSE_ID","PurchasEdge_(Y/N)","HP_TONER_UNITS","PL_REMAN_UNITS","FINALISATION_COMMENTS","RENEWAL_POSITION","PROGRAM_NAME","CUSTOMERONBOARDEDON"
"51128","OPP-048699","3/23/2020 21:02","Adam Dohm","Cheryl Glenn","Tiffany Debose","MARKET SOURCE","","Flathead Valley School District (Kalispell, Whitefish, Columbia Falls)","233 1st Ave E","Kalispell","MT","59901","","Joe Biangone","Purchasing","406-758-8392","biangonej@sd5.k12.mt.us","TONERPORT INCORPORATED","","","10293955","ESSENDANT","","12 months","Renewal","","CL091515474R4-A","SLED","97","100","98","21592","16781","38373","2452","Defend","Defend","Defend","4/15/2020 0:00","4/14/2021 0:00","4/14/2021 0:00","Won","42921984","","","","","/E/Data/Funnel/Submit/FLATHEAD VALLEY SCHOOL DISTRICT USAGE_51128.xlsx","Tiffany Debose","Tiffany Debose","3/26/2020 14:49","3/26/2020 0:00","","Bhavana P V","","","","613.97","1.6","","","","","NA","42085906","N","179","3","3/26 - Deal added on eclipse","","SMBA",""
"51126","OPP-048697","3/23/2020 19:52","Xavier Weems","","Tiffany Debose","EAST","Vladimir Jaksic","Gray Television, Inc.","Gray Television, Inc.4370 Peachtree Rd, NE.​Atlanta, Ga 30319","","GA","30319","DN042973875","Dottie Boudreau","Manager","404-266-8333","dottie@gray.tv","STAPLES, INC","","","10264576,10252948","NA","","12 months","New","","CL200351126","Commercial - Named","84","89","86","16143","7335","23478","3149","Defend","Defend","Defend","","","","AV summary and PPT sent","","","","","","/E/Data/Funnel/Submit/GRAY TELEVISION, INC USAGE_51126.xlsb","Tiffany Debose","Tiffany Debose","3/26/2020 8:55","","","Deepthi K","","","3/26/2020 0:00","3239.96","13.8","","6/24/2020 0:00","","","NA","","N","168","27","3/24/2020 - sent for specialist approval 3/26/2020 - aV sent","","MCBigDeal",""
"51125","OPP-048696","3/23/2020 18:01","Xavier Weems","","Tiffany Debose","WEST","Jenni HoGlin","STURM FINANCIAL GROUP","3033 East First Avenue","Denver","CO","80206","","","","","","STAPLES, INC","","","10264576,10252948","NA","","12 months","New","","CL200351125","Commercial - Non Named","42","87","65","10201","14198","24399","6369","Winback","Defend","Winback","","","","AV summary and PPT sent","","","","","","/E/Data/Funnel/Submit/STURM FINANCIAL GROUP USAGE_51125.xlsx","Tiffany Debose","Tiffany Debose","3/24/2020 7:49","","","Teja Ravi","","","3/24/2020 0:00","8417.66","34.5","","6/22/2020 0:00","","","NA","","N","127","67","3/24-AV Summary and PPT sent","","SMBA",""

Otherwise see What's the most robust way to efficiently parse CSV using awk? for how to do what you want with a single call to any awk.

Replace characters in a Unix text file without line break

You said :

The text file supposed to have fix length lines in it, but for some reasons, the line breaks are gone.

So you can use fold command to wrap text into at certain size and then run sed over the generated lines:

cat file.txt | fold -w <size> | sed ...

Cat with new line

you need to set IFS to newline \n

IFS=$"\n"
for groupline in $(cat file)
do
echo "$groupline";
done

Or put double quotes. See here for explanation

for groupline in "$(cat file)"
do
echo "$groupline";
done

without meddling with IFS, the "proper" way is to use while read loop

while read -r line
do
echo "$line"
done <"file"

Bash: add string to the end of the file without line break

sed '$s/$/yourText2/' list.txt > _list.txt_ && mv -- _list.txt_ list.txt

If your sed implementation supports the -i option, you could use:

sed -i.bck '$s/$/yourText2/' list.txt

With the second solution you'll have a backup too (with first you'll need to do it manually).

Alternatively:

ex -sc 's/$/yourText2/|w|q' list.txt 

or

perl -i.bck -pe's/$/yourText2/ if eof' list.txt

Concatenating Files And Insert New Line In Between Files

You can do:

for f in *.txt; do (cat "${f}"; echo) >> finalfile.txt; done

Make sure the file finalfile.txt does not exist before you run the above command.

If you are allowed to use awk you can do:

awk 'FNR==1{print ""}1' *.txt > finalfile.txt


Related Topics



Leave a reply



Submit