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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read a record split across 2 lines 1

Status
Not open for further replies.

akelabanda

Programmer
Dec 19, 2001
61
IN
Hi Guys

How can I read a record from input file which is split across 2 lines. A sample record is shown below

STLVGB0Q1_TMC121245.TLG;1
17549/17745 28-JUN-2006 09:28:00 [DECSS7] (RWED,RWED,RE,)

STLVGB0Q1_TMC121245.TLG;1 is on one line, the rest on the next line.

I need to extract the sequence number 121245 from line 1 and timestamp 28-JUN-2006 09:28:00 from the second line.

I'm a newbie on shell scripts.

Any help would be appreciated.

Cheers
Raj

UK's best mobile deals online
 
Hi

Supposing that every full line ends with an enumeration enclosed in parenthesis ( () ) and broken lines not.
Code:
sed -n '/)$/!{h;n;H;g;s/\n/ /};p' /inut/file
Works with GNU [tt]sed[/tt].

Feherke.
 
You might try a sed-oneliner to join current and next lines if a line starts with "STLVGB" or ends with "TLG;1" for instance - google for sed oneliners and take your pick.

Then all the info will be on one line for you to grep/cut/awk whatever.

You can also awk the info out of the two consecutive lines:
awk '{
if ($1 ~ /^STLVGB0Q1_TMC/)
{
seq=substr($1,14,6)
getline
print seq,$2,$3
}
}' /path/to/file


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top