Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert LF or CR with SED

Status
Not open for further replies.

FinnMan

Technical User
Feb 20, 2001
75
US
I have a single line file that I'm trying to insert some line breaks into. I seem to be failing miserably as I continue to end up with a single line.

In short:

sed -e 's/%,/%CR/g' file

I'm wanting to find each occurence of "%," and replace it with "%" and then a new line.

In exchange for your assistance, I will name my fourth child after you -- that is if the vasectomy fails.
 
awk '{x=$0;gsub(/%,/,"%\n",x);print x}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Wow..that's a beautiful sight after all the mangled text I've seen.

Instead of search/replace, could AWK instead do it after every fourth comma?

./FM

PS - I still love to see this in SED if it could be done...
 
tr '%' '\n' < file.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
# Newline after each %
{ gsub(/%/, "%\n"); print }
Code:
# Newline after every 4th column.
{ for (i=1; i<NF; i++)
    printf "%s%s", $i, i%4 ? FS : RS
  print $NF
}
Let me know whether or not this helps.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. For an introduction to Awk, see faq271-5564.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top