Need to append matching strings in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to append matching strings in a file
# 1  
Old 06-20-2013
RedHat Need to append matching strings in a file

Hi ,

I am writing a shell script to check pvsizes in linux box.

Code:
[root@pavan san_migration]#  for i in `cat vgs1`
> do
> echo "########### $i ###########"
> pvs|grep -i $i|awk '{print $2,$1,$5}'>pvs_$i
> pvs|grep -i $i|awk '{print $1}'|while read a
> do
> fdisk -l $a|head -2|tail -1|awk '{print $2,$3}'>pvs_$i1
> done
> cat pvs_$i
> cat pvs_$i1
> done
########### system ###########
system /dev/sda2 39.41g
/dev/sda2: 42.3
[root@pavan san_migration]#

Now i want to merge the output of last lines into single line like below through shell script

system /dev/sda2 39.41g 42.3

can some one help with it.

Moderator's Comments:
Mod Comment Use code tags.

Last edited by zaxxon; 06-20-2013 at 03:22 AM.. Reason: code tags, see PM
# 2  
Old 06-20-2013
Quote:
Originally Posted by nanduri
Hi ,

I am writing a shell script to check pvsizes in linux box.

[root@pavan san_migration]# for i in `cat vgs1`
> do
> echo "########### $i ###########"
> pvs|grep -i $i|awk '{printf $2,$1,$5}'>pvs_$i
> pvs|grep -i $i|awk '{print $1}'|while read a
> do
> fdisk -l $a|head -2|tail -1|awk '{print $2,$3}'>pvs_$i1
> done
> cat pvs_$i
> cat pvs_$i1
> done
########### system ###########
system /dev/sda2 39.41g
/dev/sda2: 42.3

[root@pavan san_migration]#


Now i want to merge the output of last lines into single line like below through shell script

system /dev/sda2 39.41g 42.3

can some one help with it.
Just change print to printf in first awk as highlighted above.
# 3  
Old 06-20-2013
Code:
paste pvs_$i pvs_$i1

This User Gave Thanks to anbu23 For This Post:
# 4  
Old 06-20-2013
replace the file cats with the funky code below ...
Code:
cat pvs_$i pvs_$i1 | tr "\n" "\c" | awk -F"[ c]" '{print $1, $2, $3, $5}'

This User Gave Thanks to Just Ice For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to append strings with whitespace?

Hi, Need help. This seems simple but I tried many things but failed to get what I wanted. Below is the input file: ... (7 Replies)
Discussion started by: bunny_merah19
7 Replies

2. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. UNIX for Beginners Questions & Answers

(g)awk: Matching strings from one file in another file between two strings

Hello all, I can get close to what I am looking for but cannot seem to hit it exactly and was wondering if I could get your help. I have the following sample from textfile with many thousands of lines: File 1 PS001,001 HLK PS002,004 L<G PS004,002 XNN PS004,006 BVX PS004,006 ZBX=... (7 Replies)
Discussion started by: jvoot
7 Replies

4. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies

5. Shell Programming and Scripting

Matching column value from 2 different file using awk and append value from different column

Hi, I have 2 csv files. a.csv HUAWEI,20LMG011_DEKET_1296_RTN-980_IDU-1-11-ISV3-1(to LAMONGAN_M),East_Java,20LMG011_DEKET_1296_RTN-980_IDU-1,20LMG011,20LMG 027_1287_LAMONGAN_RTN980_IDU1,20LMG027,1+1(HSB),195.675,20LMG011-20LMG027,99.9995,202.6952012... (7 Replies)
Discussion started by: tententen
7 Replies

6. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

7. UNIX for Dummies Questions & Answers

How to append portion of a file content to another file when a certain pattern is matching?

Hi ladies and gentleman.. I have two text file with me. I need to replace one of the file content to another file if one both files have a matching pattern. Example: text1.txt: ABCD 1234567,HELLO_WORLDA,HELLO_WORLDB DCBA 3456789,HELLO_WORLDE,HELLO_WORLDF text2.txt: XXXX,ABCD... (25 Replies)
Discussion started by: bananamen
25 Replies

8. UNIX for Dummies Questions & Answers

Append command and strings to a text file

hi gurus, I'm executing some commands and I want to append both the command and output to a text file. Example: echo "strings -a wicmex.o|grep '$Header'" >> tmp.txt strings -a wicmex.o|grep '$Header' >> tmp.txt echo "strings -a libwip.a|grep '$Header'" >> tmp.txt strings -a libwip.a|grep... (1 Reply)
Discussion started by: donisback
1 Replies

9. UNIX for Dummies Questions & Answers

Extraction of strings from a file, after pattern matching

I need to extract strings from a file. The file contains data like: Plan ABCD IN-+-172BB---118C2C---GGN_342-+-MM77_23--+-LAS24_3|GGK_774 | | \-LAS24_2|GGN_774 | +-AA_800_1-+-BAS_000|GGK_362 | | \-BAS_001|GGK_360 | \-DD_000T1---DAM_001|STEEL_0 Plan SHELL_1... (3 Replies)
Discussion started by: abkush
3 Replies

10. Shell Programming and Scripting

Need help with command to append strings

Greetings all, I'm in need of some help in coming up with this command which requires me to append 5 strings together: 1. echo "Status from system:" 2. `cat logs.txt` (i need the output of this command) 3. echo "Error output: " 4. `cat errors.txt`(i need the output of this command) 5.... (3 Replies)
Discussion started by: rockysfr
3 Replies
Login or Register to Ask a Question