positioning words in a line


 
Thread Tools Search this Thread
# 8  
is it divided per space or line?

this is the error I get no matter space or line
Code:
awk: (FILENAME=F1/Dean-Dean.txt FNR=1) fatal: can't redirect to `Dean-F1/Dear-Dean.txt' (No such file or directory)

Smilie
Code:
FILES="F1/*"
for X in $FILES
do
name=$(basename $X)
for i in $(cat file1.txt)
do
awk -v VM="$i" -v NM="$X" '{ for (i=1;i<=NF;i++) { if ($i ~ VM ) { print i, NR >> VM"-"NM }}}' $X
done
done


Last edited by A-V; 09-11-2012 at 12:58 PM..
# 9  
it is space separated and try below script .
one change NM=$name

Quote:
Originally Posted by A-V
is it divided per space or line?

this is the error I get no matter space or line
Code:
awk: (FILENAME=F1/Dean-Dean.txt FNR=1) fatal: can't redirect to `Dean-F1/Dear-Dean.txt' (No such file or directory)

Smilie
Code:
FILES="F1/*"
for X in $FILES
do
name=$(basename $X)
for i in $(cat file1.txt)
do
awk -v VM="$i" -v NM="$name" '{ for (i=1;i<=NF;i++) { if ($i ~ VM ) { print i, NR >> VM"-"NM }}}' $X
done
done

This User Gave Thanks to pamu For This Post:
# 10  
its funny how little thing was creating problem
the only problem now is that it is not counting the whole words per line correct
i am happy to have the word per line count before the position as well

solved.... its NF I guess instead of NR

Last edited by A-V; 09-11-2012 at 12:58 PM..
# 11  
Bug

Quote:
Originally Posted by A-V
its funny how little thing was creating problem
the only problem now is that it is not counting the whole words per line correct
i am happy to have the word per line count before the position as well

solved.... its NF I guess instead of NR
Smilie yes its NF
This User Gave Thanks to pamu For This Post:
 

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

Test Your Knowledge in Science: Computers
Difficulty: Easy
The Windows ME operating system was released in the year 2000.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

3. Shell Programming and Scripting

get few words from same line

Hello all i tried awk , cut but i think something missing i have this line @@XYMONDCHK-V1|.acklist.|developer_instead|rendy_google_yagom|1323977582|1323979382|1323979382|1|admin|test case i want cut some words to be in new line like this... (6 Replies)
Discussion started by: mogabr
6 Replies

4. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

5. Shell Programming and Scripting

How to print the words in the same line with space or to the predefined line?

HI, cat test abc echo "def" >> test output is cat test abc def the needed output is cat test abc def and so on (5 Replies)
Discussion started by: jobycxa
5 Replies

6. Shell Programming and Scripting

sort words in a line

Hi Im looking for a way, hopefully a one-liner to sort words in a line e.g "these are the words in a line" to "a are in line the these words" Thanks! (15 Replies)
Discussion started by: rebelbuttmunch
15 Replies

7. Shell Programming and Scripting

print only last two words of a line

can u help me out to print last two words of each sentence of a file. for example. contents of input file: i love songs my favourite songs sent songs all kind good buddy Ouput file should contain: love songs favourite songs sent all kind good buddy (5 Replies)
Discussion started by: pradeepreddy
5 Replies

8. Shell Programming and Scripting

how to get line number of different words if exists in same line

I have some txt files. I have to create another text file which contains the portion starting from the format "Date Sex Address" to the end of the file. While using grep -n on Date it also gives me the previous line containg Date. and also Date may be DATE in some files. My file is like this... (10 Replies)
Discussion started by: Amiya Rath
10 Replies

9. Shell Programming and Scripting

count no of words in a line

hi i have a string like str=abc def ghi jkl now i want to count the no of words in the string please help (7 Replies)
Discussion started by: satish@123
7 Replies

10. Shell Programming and Scripting

seperating the words from a line??

The line is like this +abc+def+mgh+ddsdsd+sa i.e. words seperated by +. There is a plus in the beginning. i want to conver this line to abc, def, mgh, ddsdsd, sa please provide the logic in the form of a shell script Thanks in advance (3 Replies)
Discussion started by: skyineyes
3 Replies

Featured Tech Videos