Hi, \ni like extract a single word from a file by using awk. \nI have a file dateien.txt. That contains:<\/p>\n
fuchs \ndu \nhast \ndie \nGans \ngestohlen \ngib \nsie \nwieder \nher<\/p>\n
less $sysdatsi’'dateien.txt| awk ‘NR == 1’ → works fine \nunfortunatly this loop not ( i dont get the individual words displayed)<\/p>\n
counter=1 \nwhile [ $counter -lt $Anzahl ] \ndo \necho $counter \ntemp=$(less $sysdatsi’'dateien.txt| awk ‘NR == $counter’) \necho $temp \nlet counter=counter+1<\/p>\n
done<\/p>\n
Has anybody a idea? \nThanks<\/p>","upvoteCount":1,"answerCount":2,"datePublished":"2024-08-01T06:24:01.305Z","author":{"@type":"Person","name":"spiceuser-myccr","url":"https://community.spiceworks.com/u/spiceuser-myccr"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi, \ni like extract a single word from a file by using awk. \nI have a file dateien.txt. That contains:<\/p>\n
fuchs \ndu \nhast \ndie \nGans \ngestohlen \ngib \nsie \nwieder \nher<\/p>\n
less $sysdatsi’'dateien.txt| awk ‘NR == 1’ → works fine \nunfortunatly this loop not ( i dont get the individual words displayed)<\/p>\n
counter=1 \nwhile [ $counter -lt $Anzahl ] \ndo \necho $counter \ntemp=$(less $sysdatsi’'dateien.txt| awk ‘NR == $counter’) \necho $temp \nlet counter=counter+1<\/p>\n
done<\/p>\n
Has anybody a idea? \nThanks<\/p>","upvoteCount":1,"datePublished":"2024-08-01T06:24:01.376Z","url":"https://community.spiceworks.com/t/question-for-bash-shell/1101501/1","author":{"@type":"Person","name":"spiceuser-myccr","url":"https://community.spiceworks.com/u/spiceuser-myccr"}},{"@type":"Answer","text":"\n\n
<\/div>\n
spiceuser-myccr:<\/div>\n
\ni like extract a single word from a file by using awk. \nI have a file dateien.txt. That contains:<\/p>\n
fuchs \ndu \nhast \ndie \nGans \ngestohlen \ngib \nsie \nwieder \nher<\/p>\n
less $sysdatsi’'dateien.txt| awk ‘NR == 1’ → works fine \nunfortunatly this loop not ( i dont get the individual words displayed)<\/p>\n
counter=1 \nwhile [ $counter -lt $Anzahl ] \ndo \necho $counter \ntemp=$(less $sysdatsi’'dateien.txt| awk ‘NR == $counter’) \necho $temp \nlet counter=counter+1<\/p>\n
done<\/p>\n
Has anybody a idea? \nThanks<\/p>\n<\/blockquote>\n<\/aside>\n
The issue might be due to the incorrect use of single quotes in your awk<\/code> command and the variable $sysdatsi<\/code><\/p>\nUse double-quotes instead.<\/p>\n
counter=1\nAnzahl=$(wc -l < dateien.txt) \nwhile [ $counter -le $Anzahl ]\ndo\n echo $counter\n temp=$(awk -v var=\"$counter\" 'NR == var' dateien.txt)\n echo $temp\n let counter=counter+1\ndone\n\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2024-08-01T11:20:03.519Z","url":"https://community.spiceworks.com/t/question-for-bash-shell/1101501/2","author":{"@type":"Person","name":"Rod-IT","url":"https://community.spiceworks.com/u/Rod-IT"}}]}}
Hi,
i like extract a single word from a file by using awk.
I have a file dateien.txt. That contains:
fuchs
du
hast
die
Gans
gestohlen
gib
sie
wieder
her
less $sysdatsi’'dateien.txt| awk ‘NR == 1’ → works fine
unfortunatly this loop not ( i dont get the individual words displayed)
counter=1
while [ $counter -lt $Anzahl ]
do
echo $counter
temp=$(less $sysdatsi’'dateien.txt| awk ‘NR == $counter’)
echo $temp
let counter=counter+1
done
Has anybody a idea?
Thanks
1 Spice up
Rod-IT
(Rod-IT)
August 1, 2024, 11:20am
2
spiceuser-myccr:
i like extract a single word from a file by using awk.
I have a file dateien.txt. That contains:
fuchs
du
hast
die
Gans
gestohlen
gib
sie
wieder
her
less $sysdatsi’'dateien.txt| awk ‘NR == 1’ → works fine
unfortunatly this loop not ( i dont get the individual words displayed)
counter=1
while [ $counter -lt $Anzahl ]
do
echo $counter
temp=$(less $sysdatsi’'dateien.txt| awk ‘NR == $counter’)
echo $temp
let counter=counter+1
done
Has anybody a idea?
Thanks
The issue might be due to the incorrect use of single quotes in your awk
command and the variable $sysdatsi
Use double-quotes instead.
counter=1
Anzahl=$(wc -l < dateien.txt)
while [ $counter -le $Anzahl ]
do
echo $counter
temp=$(awk -v var="$counter" 'NR == var' dateien.txt)
echo $temp
let counter=counter+1
done
2 Spice ups