Script to fill in sed input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to fill in sed input
# 1  
Old 01-31-2012
Script to fill in sed input

Hello

I have a file with list of numbers
Code:
380634062
380907172
380733031
380733032
380896961
380896962
381067621
381067622
380995932

I would like to find a way to fill in a sed command delete pattren
Code:
sed -i '/$number_from_list/d' -e '/$second_from_list/d' -e ... etc

so I can end up with a long sed command which contains all search pattern and run it once against the file.


I had my script setup to use for loops to loop through the content of my text file and do delete everytime it takes a number from the list. but this makes it very very slow! I'm trying to run all numbers against the file and delete all lines which starts with those numbers once and for all.

Thank you

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data
# 2  
Old 01-31-2012
Trying to use sed for this makes it much harder than it needs to be.

Code:
grep -f excludefile inputfile > outputfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-31-2012
grep -vf , no?
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 01-31-2012
Yes, good point. -v to reverse the output to exclude the matches instead of including them.
# 5  
Old 01-31-2012
oh yeah I did that on my initial run to do invert stuff!

the thing is its running! but still very slow! is there is a faster way?
# 6  
Old 01-31-2012
The grep version is extremely fast. Please show exactly how you're using it, there must be other problems with your script.

If the files are enormous(hundreds of megs and up), the limit may be your disk speed.
# 7  
Old 01-31-2012
Alternatively try:
Code:
awk 'NR==FNR{A[$1]=1;next}!A[$1]' excludefile inputfile > outputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to fill the entire row of Excel file with color based on pattern match

Hi All , I have to write one Perl script in which I need to read one pre-existing xls and based on pattern match for one word in some cells of the XLS , I need to fill the entire row with one color of that matched cell and write the content to another excel Please find the below stated... (2 Replies)
Discussion started by: kshitij
2 Replies

2. Shell Programming and Scripting

sed with standard input not working

I am trying use sed to replace a string in a file with input string passed, but it is not replacing the string. instead it replace as $1. Please find below the code. echo $1 sed -i.$now "s/http.*.myservice.*.war/$1/" tempfile.xml I am running above code as below myscript.sh ReplaceString... (4 Replies)
Discussion started by: sakthi.99it
4 Replies

3. Emergency UNIX and Linux Support

Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command dd if=/dev/zero of=file_2GB bs=2048000 count=2000 We are planning to automate the task where taking input for % of size as one input and the name of the file system... (8 Replies)
Discussion started by: chandu123
8 Replies

4. Shell Programming and Scripting

sed execution with input from keyboard

> sed '' Hello hi Hello output How hi output ^D How > sed should take each line as input, process and output the result. In the above scenario the input is passed from keyboard and the output of 'Hello' as you can see is displayed on the screen after 'hi' is passed as input but not as... (1 Reply)
Discussion started by: loggedin.ksh
1 Replies

5. Shell Programming and Scripting

Script which fill data in XML file

Hello, I need help for writing a script that fills already generated xml file with data from oracle database and random sequences. For example if we have the following tags: <ns1:message> <ns1:messageId> </ns1:messageId> <ns1:languageCode> </ns1:languageCode>... (10 Replies)
Discussion started by: zb99
10 Replies

6. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

7. Shell Programming and Scripting

Sed with unescaped input

a shell script variable from user input, via read, will typically have special characters in it - i.e. sip:29384902834!someServer.com@someOtherServer.com this value has to stay formatted like this because it being used by curl in a post to php. but it is also being used by sed to replace the... (4 Replies)
Discussion started by: Gripp
4 Replies

8. Shell Programming and Scripting

Reading from input with sed

I am trying to edit a file in shell script using sed. I need to get the input from command line suppose script.sh sed"/s place=/place=california/g" > /root/user/mark.txt echo " place changed " the above code searches for string place in the file mark.txt and replaces with place=... (5 Replies)
Discussion started by: sriki32
5 Replies

9. Shell Programming and Scripting

SED command using multiple input files

What is the syntax to use multiple input files in a SED command. i.e. substitute a word with a phrase in every file in a directory. for every file in /usr/include that has the word "date" in the file grep -l '\<date\>' /usr/include/*.h find each occurrence of the word "time" in the file &... (3 Replies)
Discussion started by: sheoguey
3 Replies

10. Shell Programming and Scripting

script to fill up disk space for testing purpose

Hello everyone I am new to this forum I am working on a project and needed a test script to fill up a disk partition /tmp/data to see how the program fails. The system I am working on is a redhat 5.3. Is there anything out there? Thanks. (10 Replies)
Discussion started by: dp100022
10 Replies
Login or Register to Ask a Question