LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-31-2016, 04:50 PM   #1
sam@
Member
 
Registered: Sep 2013
Posts: 31

Rep: Reputation: Disabled
Command to add a line


I have a file that looks like

Code:
LG1  GLEAN   task    14023   15966   0.475952        +       .       ID=C.ca3;event_id=C.ca524;
LG1  GLEAN   dependent     14023   15966   .       +       0       Header=C.ca3;
LG2  GLEAN   task    20087   31342   0.0164527       -       .       ID=C.ca4;event_id=C.ca245;
LG2  GLEAN   dependent     31146   31342   .       -       0       Header=C.ca4;
LG2  GLEAN   dependent     30427   30541   .       -       1       Header=C.ca4;
I want to add a line having tab3 as upper with same entries as in the line with task

The output file should look like this
Code:
LG1  GLEAN   upper    14023   15966   0.475952        +       .       ID=C.ca3.1;event_id=C.ca524;
LG1  GLEAN   task    14023   15966   0.475952        +       .       ID=C.ca3;event_id=C.ca524;
LG1  GLEAN   dependent     14023   15966   .       +       0       Header=C.ca3;
LG2  GLEAN   upper    20087   31342   0.0164527       -       .       ID=C.ca4.1;event_id=C.ca245;
LG2  GLEAN   task    20087   31342   0.0164527       -       .       ID=C.ca4;event_id=C.ca245;
LG2  GLEAN   dependent     31146   31342   .       -       0       Header=C.ca4;
LG2  GLEAN   dependent     30427   30541   .       -       1       Header=C.ca4;
I tried this
sed 's/\(.*\)task\(.*\)\(ID=[^.]*\)[^;]*\(;.*\)/\1upper\2\3\4\n&/'

But it didnt work. Is there any change i need to make or any other suggestions that can help me obtained the required fileoutput.

Thanks!

Last edited by sam@; 08-31-2016 at 11:16 PM.
 
Old 08-31-2016, 06:53 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,648

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
Should work - might be cleaner to use the hold space
Code:
sed '/task/ {h;s/task/upper/;G}'
 
Old 08-31-2016, 11:18 PM   #3
sam@
Member
 
Registered: Sep 2013
Posts: 31

Original Poster
Rep: Reputation: Disabled
Sorry for being a bit unclear but I do need the id name as ID=*.1 for the lines with upper
Will that be an easy fix?


LG1 GLEAN upper 14023 15966 0.475952 + . ID=C.ca3.1;event_id=C.ca524;
LG2 GLEAN upper 20087 31342 0.0164527 - . ID=C.ca4.1;event_id=C.ca245;
 
Old 09-01-2016, 02:49 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,508

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
So, simply add the additional change:
Code:
sed '/task/ {h;s/task/upper/;s/ID[^;]*/&.1/;G}'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to add an lvm from the command line Thaidog Red Hat 5 10-30-2010 09:35 PM
Add printer command line allancth Linux - Newbie 3 04-01-2009 06:06 AM
howto add a mouse on the command line? Fred Caro Linux - Newbie 4 12-29-2008 12:50 PM
Add user from Command line darkapolloslx Linux - Newbie 1 12-29-2008 12:45 AM
how to add icon with the command line jonsharland Linux - General 1 10-17-2002 03:59 AM


All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration