Computing.Net > Forums > Unix > sed/awk - line feeds?

sed/awk - line feeds?

Reply to Message Icon

Original Message
Name: Scott Smith
Date: June 30, 2003 at 13:27:17 Pacific
Subject: sed/awk - line feeds?
OS: unix
CPU/Ram: n/a
Comment:

I am using a ksh script to parse/analyze some text files - files that have records that are over multiple lines. I have used sed and awk in the past; however, I am having trouble with carriage returns and line feeds. I can separate the multiple line records using awk. Now I just need to understand:

1) Using sed/awk to search and replace strings that may contain line feeds/carriage returns (file may be unix or dos)
2) Using sed/awk to substitute line feeds/carriage returns for a string
3) Using sed/awk to search/replace for EOF
4) I don't understand the difference between the unix/dos files, and what that means for searching for line feeds.

I know how to use "^" and "$" in sed/awk to find things at the begining or end of lines, just not how to find things that straddle a line feed within a record.

I appreciate any examples that anyone could provide to help me understand!

Here is a sample input file for any example sed/awk syntax to run on:
Record1
DataA
DataB
DataC

Record2
DataD
DataE
DataF

Regards,
Scott


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: June 30, 2003 at 15:29:55 Pacific
Subject: sed/awk - line feeds?
Reply: (edit)

Hi:

This replaces the last character if the octal value is 15 or 32, Control-m and Control-z respectively:
sed 's/'"$(printf '\015')"'$//
s/'"$(printf '\032')"'$//' filename

You probably can modify it to fit your needs.

Regards,


Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: James Boothe
Date: July 1, 2003 at 11:39:29 Pacific
Subject: sed/awk - line feeds?
Reply: (edit)

Are your logical records chopped into individual lines (such as 80 characters each), and now you need to grep for patterns that might span a record segment?

If that is the case, would it make sense to put those pieces back together into single lines, then process the whole records?

If so, it is easy to do that as long as you can clearly identify which lines need to be reconcatenated. On the same pass, sed can reconcatenate (remove the newline characters), then do the grep on the reconcatenated logical record.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: sed/awk - line feeds?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge