Append has prefix in while loop


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Append has prefix in while loop

I was using below script to grep one file. I need to append the output using prefix

Data of all-Vms-1.txt
Code:
server-1 frame-1 LUN001
server-2 frame-1 LUN002

Data of all-vm-unix.txt

Code:
server-1     24
server-2     50

Script used
Code:
while read -r g h ;
do
cat all-Vms-1.txt |grep -i $g |awk '$0="frame "$0'|sed -e "s/frame/${g} ${h}/" >> all-vm-unix-with-vc-2

done < all-vm-unix.txt

I need output like this

Code:
server-1 24 server-1 frame-1 LUN001
server-2 50 server-2 frame-1 LUN002

But Now it was echo in next line

Code:
server-1 24 
server-1 frame-1 LUN001
server-2 50 
server-2 frame-1 LUN002


Last edited by Scrutinizer; 3 Days Ago at 06:00 AM.. Reason: quote tags -> code tags
# 2  
the usual approach:
Code:
awk 'FNR==NR {f1[$1]=$0;next} $1 in f1 {print $0, f1[$1]}' all-Vms-1.txt all-vm-unix.txt

# 3  
Hi vgersh99

I think it was checking case sensitive and ignore if it dont match. How to ignore case sensitive
# 4  
Use the tolower(str) function to changes strings to lowercase where appropriate to make it case insensitive...

Last edited by Scrutinizer; 3 Days Ago at 06:36 AM..
# 5  
Quote:
Originally Posted by Scrutinizer
Use the tolower(str) function to changes strings to lowercase where appropriate to make it case insensitive...
Sorry where i need to use this code
# 6  
Quote:
Originally Posted by ranjancom2000
Sorry where i need to use this code
To adjust vgersh99's suggestion try:
Code:
awk '{i=tolower($1)} FNR==NR {f1[i]=$0;next} i in f1 {print $0, f1[i]}' all-Vms-1.txt all-vm-unix.txt

This User Gave Thanks to Scrutinizer For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #571
Difficulty: Medium
A simple units bug in the Mars Climate Orbiter caused an error which resulted in loses of over $125M USD in 1999.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Uniq prefix from a start and end prefix

Dear All, assume i have a file with content: <Start>6000</Start> <Stop>7599</Stop> the output is: 6000 7000 7100 7200 7300 7400 7599 how should we use any awk, sed, perl can do this task, means to extract the uniq prefixes from the start and stop prefix. Thanks Jimmy (3 Replies)
Discussion started by: jimmy_y
3 Replies

2. UNIX for Advanced & Expert Users

Prefix/Suffix on same file

Hi, I want to add prefix and suffix on line# 205 using SED or AWK and want to change on the same file without creating new file. This command will be used in the bash script Am using Bash shell Regards Nayaj (3 Replies)
Discussion started by: Nayaj
3 Replies

3. Shell Programming and Scripting

Removing only Prefix string (!)

Hello everyone, I want to remove only prefix ME_ from all the values that are present in the FILEA. Below code I'm using for this. sed 's/ME\_//g' FILEA > FILEB Using the above code, all ME_ values are getting removed from the file. But the problem here is I want to remove only Prefix ME_... (4 Replies)
Discussion started by: ed_9
4 Replies

4. Shell Programming and Scripting

Find all images, append unique prefix to name and move to different directory

Hi, I have a directory with Multiple subdirectories and 1000s of pictures (jpg) in each directory. The problem is that each directory has a 001.jpg in them. I want to append a unique name (the directory_name)would be fine. and then move them to one main backup directory once they have been... (1 Reply)
Discussion started by: kmaq7621
1 Replies

5. Shell Programming and Scripting

append to same string variable in loop

I want to append values to same string variable inside a recursive function that I have .. I do not want to write to any file but use a variable.. Can anyone please help with it? Thanks in advance. (6 Replies)
Discussion started by: Prev
6 Replies

6. Shell Programming and Scripting

Prefix integer with zeros

I want an integer to be prefix with some zeros so that it makes the integer 5 digit always: For eg: if the digit is 8 i need 00008 if the digit is 8976 ans sud be 08976. Could anyone say simple and efficient commands to this in ksh. Thanks a lot... (4 Replies)
Discussion started by: PRKS
4 Replies

7. UNIX for Dummies Questions & Answers

--prefix question

OK, now I just feel plain silly asking this. But I am very much a beginner at compiling and installing Unix software, so... When setting the prefix, do you also have to specify the directory the files reside in? For example, lets say I am installing cURL in /usr/local Would I set the prefix... (1 Reply)
Discussion started by: RobertSubnet
1 Replies

8. Shell Programming and Scripting

prefix suffix to each argument

Hi, I have a variable, which contains comma separated values. Something like. StringA="abc,def,ghi,jkl" I want to apply prefix and suffix to each value in the string without using any loops. Say if Prefix is Pre_ and Suffix is _Suf then I need to get ... (1 Reply)
Discussion started by: tostay2003
1 Replies

9. Shell Programming and Scripting

how to check prefix and postfix

i want to check the command line argument $1 . which ends with .XYZ eg if $1 is unix.XYZ i want to check whether it ends with XYZ or not if it didnot ends with XYZ.. then it has to exit (2 Replies)
Discussion started by: mail2sant
2 Replies

10. UNIX for Dummies Questions & Answers

remove filename prefix

I've got a bunch of files called oldabc, olddef etc. i want to copy these to be abc, def.... I can do this with file extensions....but can get the logic to work for prefixes. All the files I am interested in have a prefix of 'old'. This loop is no good for me....it looks at the content... (2 Replies)
Discussion started by: peter.herlihy
2 Replies

Featured Tech Videos