Results 1 to 5 of 5
Hi all,
I'm writing shell script on my own
I'm at the last step in the script i didn't seem to get it right
Here is problem:
I have 2 ...
- 01-11-2008 #1
How to get this?
Hi all,
I'm writing shell script on my own
I'm at the last step in the script i didn't seem to get it right
Here is problem:
I have 2 files.
file1.txt
file2.txtCode:AAA BBB CCC EE
I need output file like,Code:AAA34 BBB66 CCC DDD EE&something FF GG
How to do this?Code:AAA34 BBB66 CCC EE&something
I thought about diff and comm ...but doesn't seems to work for me.
Any thoughts ?- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 01-11-2008 #2
It's not clear what you're trying to do here.
The output file looks just like the the first, second, third, and fifth lines of the second input file, with the first input file ignored completely.
In other words, I don't think we can guess your intention by just looking at the input and desired output. You'll have to tell us more completely what you want.--
Bill
Old age and treachery will overcome youth and skill.
- 01-11-2008 #3
Ok..this is what i want :
I want to grep lines from file2 which begins with the content of file1.
Example:
I got a file (say file1) which will have few words like,
And another file (file2.txt) has the following contents:Code:This That These line
[code]
This is line1.
That is line2 .
These are line3 and 4.
And finally i have
Dont Get this line
[\code]
I want to grep only those lines from file2 which begins with the contents from file1.
the desired output :
And these two lines are omiitedCode:This is line1. That is line2 . These are line3 and 4.
becauseCode:And finally i have Dont Get this line.
we don't have start wording in file1.Code:"And finally i have"
Though the word "line" is available in file1.Code:"Dont Get this line"
Since this sentence begins with the word "Dont" we skip this too.
Any ideas?- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 01-11-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
output:Code:awk 'FNR==NR{ a[$0]=$0 next } { for ( items in a ) { if ( items ~ $0 ) { print items } } }' file2 file1
Code:# ./test.sh AAA34 BBB66 CCC EE&something
- 01-11-2008 #5
i found a solution:
I needed grep with ^ option
so simpleCode:#----- The file to read myFile="file1.txt" myLine="" i="1" while [ 1 ] do read myLine || break F1=$(echo $myLine | awk '{ print $1 }') grep '^'$F1 file2.txt >> file3.txt done < $myFile exit;
Though i love C cprogramming,shell script is very useful and powerful
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote