Sponsored Content
Top Forums Shell Programming and Scripting Need help parsing data with sed and/or nawk Post 302604571 by joeyg on Monday 5th of March 2012 11:04:05 AM
Old 03-05-2012
Tools What about something like?

Code:
$ cat sample1.txt
Treatment
      ,parmeter1=value
      ,parmeter2=value
      ,parmeter3=value
      ,parmeter4=value
      ,parmeter5=value
      ,parmeter6=value
      ,parmeter7=value
      ,parmeter8=value
      ,parmeter9=value
      ,parmeter10=value
      ,parmeter11=value
      ,parmeter12=value
      ,parmeter13=value
      ,parmeter14=value
      ,parmeter15=value
;;
Treatment
      ,parmeter1=value
      ,parmeter2=value
      ,parmeter3=value
      ,parmeter4=value
      ,parmeter5=value
      ,parmeter6=value
      ,parmeter7=value
      ,parmeter8=value
      ,parmeter9=value
      ,parmeter10=value
      ,parmeter11=value
      ,parmeter12=value
      ,parmeter13=value
      ,parmeter14=value
      ,parmeter15=value
;;

$ sed 's/;;/;;~/g' sample1.txt | tr -d "\n" | tr "~" "\n" | tr -s " "
Treatment ,parmeter1=value ,parmeter2=value ,parmeter3=value ,parmeter4=value ,parmeter5=value ,parmeter6=value ,parmeter7=value ,pa
rmeter8=value ,parmeter9=value ,parmeter10=value ,parmeter11=value ,parmeter12=value ,parmeter13=value ,parmeter14=value ,parmeter15
=value;;
Treatment ,parmeter1=value ,parmeter2=value ,parmeter3=value ,parmeter4=value ,parmeter5=value ,parmeter6=value ,parmeter7=value ,pa
rmeter8=value ,parmeter9=value ,parmeter10=value ,parmeter11=value ,parmeter12=value ,parmeter13=value ,parmeter14=value ,parmeter15
=value;;

I put a ~ character at end, so when I get rid of new-lines, I can put a Return back in the data. I also suppress extra blank space characters.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in sed or nawk replace RE

Dear Friends, I am trying to replace the following pattern , But I cant understand how to express the RE in this case . Please help me with a sed command to replace . (Address = 918h : Initial = 0000h : RD /WR (Address = 91Ah : Initial =... (2 Replies)
Discussion started by: user_prady
2 Replies

2. Shell Programming and Scripting

sed selective data parsing

i have file in the following format *RECORD* *FIELD NO* 123456 *FIELD TX* this is a sample entry *FIELD SA* See Also *FIELD RF* References *FIELD CS* Clinical Symptoms *FIELD AV* Allelic Variants *FIELD EH* Edit History *RECORD* *FIELD NO* 123456 (1 Reply)
Discussion started by: dunstonrocks
1 Replies

3. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

4. Shell Programming and Scripting

parsing(xml) using nawk/awk

Hi , I have an xml format as shown below: <Info> <last name="sean" first name="john"/> <period="5" time="11"/> <test value="1",test2 value="2",test3 value="3",test4 value="5"> <old> <value1>1</value1> <value2>2</value2> </old> <new> <value1>4</value1> <value2>3</value2> </new>... (1 Reply)
Discussion started by: natalie23
1 Replies

5. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

Sed/Nawk help

Hi all, I have the following piece of code which reformats a file but the part that isn't working converts a date from dd mmm ccyy format to 2 fields containing dd/mm/ccyy,ccyy-mm-dd hh:mm:ss.000000 This is for a DB2 load file. The problem I have is that the input dd values (the dd variable... (2 Replies)
Discussion started by: dazedandconfuse
2 Replies

7. Shell Programming and Scripting

XML parsing using nawk help needed

i need one help, below is one more xml file with diff pattern i tried it but dint get it , iam sure its a peice of cake for you guys. <xn:MeContext id="LSVLKY001"> <xn:ManagedElement id="1"> <un:RncFunction id="1"> <un:UtranCell... (2 Replies)
Discussion started by: tech_frk
2 Replies

8. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

9. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies
SA1(8)								Linux User's Manual							    SA1(8)

NAME
sa1 - Collect and store binary data in the system activity daily data file. SYNOPSIS
/usr/lib/sysstat/sa1 [ --boot | interval count ] DESCRIPTION
The sa1 command is a shell procedure variant of the sadc command and handles all of the flags and parameters of that command. The sa1 com- mand collects and stores binary data in the /var/log/sysstat/sadd file, where the dd parameter indicates the current day. The interval and count parameters specify that the record should be written count times at interval seconds. If no arguments are given to sa1 then a single record is written. The sa1 command is designed to be started automatically by the cron command. OPTIONS
--boot This option tells sa1 that the sadc command should be called without specifying the interval and count parameters in order to insert a dummy record, marking the time when the counters restarts from 0. EXAMPLE
To collect data (including those from disks) every 10 minutes, place the following entry in your root crontab file: 0,10,20,30,40,50 * * * * /usr/lib/sysstat/sa1 1 1 -S DISK Debian note The Debian sysstat package has already placed such an entry in your system crontab. Please refer to the /usr/share/doc/sys- stat/README.Debian file for details. FILES
/var/log/sysstat/sadd Indicate the daily data file, where the dd parameter is a number representing the day of the month. AUTHOR
Sebastien Godard (sysstat <at> orange.fr) SEE ALSO
sar(1), sadc(8), sa2(8), sadf(1), sysstat(5) http://pagesperso-orange.fr/sebastien.godard/ Linux FEBRUARY 2012 SA1(8)
All times are GMT -4. The time now is 05:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy