You are not logged in.
Pages: 1
Hi!
I'm working on a radio script with several functions, but i need your help to continue. I want to search for a spefic string in a file. The files content is like:
Super Hot Girls Radio Channel;http://lovepotion.org:666
Sir Camelot Danish Radio;kingandnight.org:231
So if i search for "io", this will appear:
Super Hot Girls Radio Channel
Sir Camelot Danish Radio
Last edited by svanberg (2009-07-26 22:34:13)
Offline
if i understood you, this is what you want:
grep "io" ./file.ext
Offline
You should tell your search function that io is the whole string, and no subset of whatever it finds. If not it will simply print all matches - not the exact ones but, as you can see, also the strings that contain your query and do not match it exactly.
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
simply,
awk -F ';' '/io/ {print $1}' ./file.txt
but, if in a script, and a variable is the search term you've got to switch the quoting like so
term="$1"
awk -F ';' "/$term/"'{print $1}' $file
Last edited by brisbin33 (2009-07-22 21:39:00)
//github/
Offline
but, if in a script, and a variable is the search term you've got to switch the quoting like so
term="$1" awk -F ';' "/$term/"'{print $1}' $file
You should also declare "file"
Last edited by Boris Bolgradov (2009-07-22 21:44:48)
Offline
brisbin33 wrote:but, if in a script, and a variable is the search term you've got to switch the quoting like so
term="$1" awk -F ';' "/$term/"'{print $1}' $file
You should also declare "file"
yeah, i figured that was implied. i just meant to highlight the fact that something like $term wouldn't get evaluated if you used the single quotes as in the first literal-search example. thanks go to procyon for showing me that trick.
//github/
Offline
When using this:
awk -F ';' "/rad/"'{print $1}' $file
I get this output:
Mix Megapol
The Voice 105,9
But i don't want to search the whole line, just all text before the ";" char and the search should not be case sensitive.
Mix Megapol;mms://streaming.sbsradio.se/03872_MixMegapol_high
The Voice 105,9;mms://streaming.sbsradio.se/03872_TheVoice_high
Offline
You could do a grep, pipe it to sed to remove everything after the ";", and repeat the grep to make sure the match wasn't in the second half.
Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.
Offline
Try this:
cat file.txt | cut -d ';' -f1 | grep -i 'io'
This will print everything that contains 'io' before ';'
Last edited by Boris Bolgradov (2009-07-23 11:20:29)
Offline
I'm no awk guru but this seems to work.
echo "Mix Megapol;mms://streaming.sbsradio.se/03872_MixMegapol_high
The Voice 105,9;mms://streaming.sbsradio.se/03872_TheVoice_high
The Rad;mms:/streaming.sbsradio.se/03872_The_rad" | awk 'BEGIN{OFS=FS=";";IGNORECASE=1}$1 ~ /rad/{print$1}'
Offline
I'm no awk guru but this seems to work.
echo "Mix Megapol;mms://streaming.sbsradio.se/03872_MixMegapol_high The Voice 105,9;mms://streaming.sbsradio.se/03872_TheVoice_high The Rad;mms:/streaming.sbsradio.se/03872_The_rad" | awk 'BEGIN{OFS=FS=";";IGNORECASE=1}$1 ~ /rad/{print$1}'
this line seems to work best; throwing a second | grep "rad" on the end of mine would also ensure that the match is only for the first portion, but that's a bit of a hack.
//github/
Offline
Thanks for all your help. Now I am able to continue again.
Offline
Pages: 1