Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2012
Registered User
 

Join Date: Dec 2011
Posts: 31
Thanks: 22
Thanked 1 Time in 1 Post
Help with shell scripting

Shell Scripting

i want to delete bottom line and put in to upper line if it have specific word.

ex

Code:
Dell 14 20 31 
Hp 16 19
Logi 29 89 
HP 21 30
Iph 15 60 59
Hp 20 21 22

Output:

Code:
Dell 14 20 31 16 19
Logi 29 89 21 30
Iph 15 60 59 20 21 22

Thanks in Advance.........

Last edited by Scott; 02-08-2012 at 02:31 PM.. Reason: Code tags
Sponsored Links
    #2  
Old 02-08-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts
Try this...

Code:
sed -n 'H; $ {x;s/\n[Hh][Pp]//g;p}' infile

--ahamed
Sponsored Links
    #3  
Old 02-08-2012
Registered User
 

Join Date: Dec 2011
Posts: 31
Thanks: 22
Thanked 1 Time in 1 Post
Thanks a lot Ahmamed ..


But can you help on this....

i have same thing but little bit complex..

file1.txt have below input

Code:
6120.log:$_port_info = 001200/port_2_dev_16
6120.log:$_port_info = 001200/port_6_dev_17
6120.log:$_port_info = 001200/port_10_dev_18
6120.log:$_port_info = 001200/port_8_dev_7
6120.log:$_port_info = 001200/port_0_dev_5
6120.log:$_port_info = 001200/port_4_dev_6
6120.log:001200/port_2_dev_16
6120.log:vswr:  -0.7[dB]
6120.log:001200/port_6_dev_17
6120.log:vswr:   0.0[dB]
6120.log:001200/port_10_dev_18
6120.log:vswr:  -0.7[dB]
6120.log:001200/port_8_dev_7
6120.log:vswr:  17.3[dB]
6120.log:001200/port_0_dev_5
6120.log:vswr:  21.9[dB]
6120.log:001200/port_4_dev_6
6120.log:vswr:  19.5[dB]

i need out put like this file2

I want to remove all .log and [db] from all line also remove all unnecessary string and give me output like below......

Code:
6120 122  NoVSWR
6120 126  NoVSWR
6120 1210 NoVSWR
6120 128  NoVSWR
6120 120  NoVSWR
6120 124  NoVSWR
6120 122  -0.7
6120 126   0.0
6120 1210 -0.7
6120 128  17.3
6120 120  21.9
6120 124  19.5

Please help me with this .....again thanks a lottttttttttt

Last edited by Scott; 02-08-2012 at 02:30 PM.. Reason: Please use code tags
    #4  
Old 02-08-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts
Where is the second column data coming from? 122, 120 etc

--ahamed
Sponsored Links
    #5  
Old 02-08-2012
Registered User
 

Join Date: Dec 2011
Posts: 31
Thanks: 22
Thanked 1 Time in 1 Post
Ahamed


Code:
6120.log:$_port_info = 001200/port_2_dev_16

it will remove all unnecessary string 001200/port_2_dev_16 but i need 12 and 2 with is after port_.


Code:
6120.log:$_port_info = 001200/port_2_dev_16 = 6120 122

001200=12  and /port_2 =2 so combine it 122

Thanks for your quick replay brother...

---------- Post updated at 02:14 PM ---------- Previous update was at 12:46 PM ----------

any help please ...........................

Last edited by Scott; 02-08-2012 at 02:31 PM.. Reason: Code tags
Sponsored Links
    #6  
Old 02-08-2012
ahamed101's Avatar
root is god!!!
 

Join Date: Sep 2008
Location: India
Posts: 1,478
Thanks: 33
Thanked 382 Times in 377 Posts

Code:
awk -F[:/_=] '{end="NoVSWR";sub(/.log/,"");num=$1;gsub(/[0 ]/,"",$(NF-4));port=$(NF-4)$(NF-2)}  
$2!="$"{getline;end=$NF+0}{print num,port,end}' infile

--ahamed
Sponsored Links
    #7  
Old 02-08-2012
Registered User
 

Join Date: Dec 2011
Posts: 31
Thanks: 22
Thanked 1 Time in 1 Post
Hi

I am getting below error when i run it....

my Script is below...

Code:
egrep -e '_dev|vswr:' *.log > $VSWR

awk -F[:/_=] '{end="NoVSWR";sub(/.log/,"");num=$1;gsub(/[0 ]/,"",$(NF-4));port=$(NF-4)$(NF-2)}$2!="$"{getline;end=$NF+0}{print num,port,end}' $VSWR


Last edited by Franklin52; 02-09-2012 at 03:18 AM.. Reason: Please use code tags for code and data samples, thank you
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl scripting or shell scripting? Anna Hussie Web Programming 1 04-20-2011 04:08 AM
Shell Scripting vs Perl scripting Pouchie1 What's on Your Mind? 2 02-10-2011 12:21 PM
Shell scripting vs Perl scripting Pouchie1 What's on Your Mind? 14 09-06-2010 09:48 PM
Call Shell scripting from Perl Scripting. anupdas Shell Programming and Scripting 2 02-12-2010 07:07 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM



All times are GMT -4. The time now is 04:42 AM.