Read a file and create egrep variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a file and create egrep variable
# 1  
Old 02-25-2010
Read a file and create egrep variable

I want to create a egrep variable from a file.
For example:
Code:
string=`cat query.txt`
cat myfile.txt | egrep "$string"

The string variable file has a list of one or multiple lines
So the end result of:
Code:
cat myfile.txt | egrep "$string"

would be:
Code:
cat myfile.txt | egrep "test1|test20|test33"

I can not figure out how to read the file line by line and put a | between all but the last line and if the file only has one entry, to not put any |
# 2  
Old 02-25-2010
As a hint, perhaps:
Code:
$ cat file1
a
b
c
$ paste -sd\| file1
a|b|c

You have a lot of useless uses of cat there.
Code:
cat file | grep ...

can easily be done using
Code:
grep ... file

# 3  
Old 02-25-2010
Thank you Scottn, the paste command works for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Lines from One file.. and create another.. and

Hello Members, I have one file which contains million of supplier code. I need to load these codes into database 1000 at a time. Database procedure reads from an external table which is based on the unix files. All I want to do is to read from the bigger file e.g. MAIN_FILE.txt and create... (1 Reply)
Discussion started by: chetanojha
1 Replies

2. Shell Programming and Scripting

Read log file to create Performance index

I am required to create a CSV file reading last 200000 lines form a log file. I have to grep 3 parameters from this log file and write these parameters in the .csv file, with time stamp. This script will be setup in a cron job which will run every 10 minutes. I have written the script but it is... (5 Replies)
Discussion started by: Crazy_Nix
5 Replies

3. Shell Programming and Scripting

Script to read through a file and create new users/assign them to groups in Ubuntu

Hi all. I need a shell script that can, in short, read through a text file line by line and create a new user in Ubuntu, as well as assign that user to a group. The format of the text file is not important but preferably: 'username:group'. I don't have much programming knowledge no matter shell... (3 Replies)
Discussion started by: LewisWeekly
3 Replies

4. Shell Programming and Scripting

Egrep a variable

I am trying a bash shell script to egrep a variable. For example, I will be taking input from user and want to use it with egrep -v as follows - lvg=rootvg echo -e "Enter local vg name \c "; read lvg egrep -v '#|x|y|$lvg' /filename >> /newfilename Please advice, how I can do that? ... (2 Replies)
Discussion started by: atanubanerji
2 Replies

5. Shell Programming and Scripting

How to create a shell script to read a foldername from a text file and go to the folder?

Hi, I am trying to write a shell script which can read folder names from a text file and then go to the folder and picks up a xml file and write on my sipp script so that I can run the sipp script. For example: I have a text file called thelist.txt where I have provided all the folders... (7 Replies)
Discussion started by: pm1504
7 Replies

6. UNIX for Dummies Questions & Answers

Read a flat file, evaluate and create output. UNIX SCRIPT.

Hi all, I have a flat file as below; 470423495|1||TSA-A000073800||1|||1 471423495|1||TSA-A000073800||5|||5 472423495|1||TSA-A000073800||2|||7 473423495|1||TSA-A000073800||3|||3 I like to create a Unix script. The script have to valuate the last two columns, if the values are... (4 Replies)
Discussion started by: mrreds
4 Replies

7. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

8. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

9. Shell Programming and Scripting

read mp3 filename and create one XML for each file

Hi: I have a collection of mp3s and I need to create 1 xml file per mp3. I have: recording1.mp3 recording2.mp3 etc and I want to generate this kind of files. recording1.xml recording2.xml and inside each xml file I need to add a url prefix and then the filename at the end. ... (4 Replies)
Discussion started by: jason7
4 Replies

10. Shell Programming and Scripting

Read words from file and create new file using K-shell.

Hi All, Please help me in creating files through K-shell scripts. I am having one file in this format. OWNER.TABLE_NAME OWNER.TABLE_NAME1 OWNER1.TABLE_NAME OWNER1.TABLE_NAME1 I want to read the above file and create new file through k shell script. The new file should looks like this.... (4 Replies)
Discussion started by: bsrajirs
4 Replies
Login or Register to Ask a Question