How to remove string in the text file ? Bash script
Hello
I have a text file which include: Code:
https://myserver/xa/if?took1=324234234345345345 Code:
https://myserver/xa/if?took1= help... |
Code:
awk -F/ '{print $5}' file |awk -F= '{print $2}' >newfile |
Of course it is more common to do this kind of operation (replacement/deletion) with sed:
Code:
sed -e s/https:"\/""\/"myserver"\/"xa"\/"if?took1=// file >newfile sed -e s/pattern/newpattern/ Since your pattern includes several / characters you have to do the bizarre quoting and escaping seen in the live above so it knows which ones are literal and which are part of the sed script. |
Quote:
If this address will change for example Code:
https://myserver/xa/if?took1= > https://yourserver/xa/if?took1= what should I do ? thanks for fast answer |
Code:
awk -F = '{print $1}' filename Change $1 to $2 to print everything after the "=". Code:
awk -F = '{print $1}' filename > new filename |
Thanks a lot !
This is a big help for me ! greetings from Germany ! |
This is why I mentioned sed - it is more common to do something like this:
Code:
sed -e s/myserver/yoursever/ file >newfile |
Quote:
Code:
sed -e 's|https://myserver/xa/if?took1=||' file >newfile |
Quote:
Follow it up with the command to print only the fields you want to see and Bob's your uncle, as the Brits say. ;) You can learn a lot more about how to use sed and awk on this page. It's well worth taking the time to read (and work through) them. |
Quote:
Code:
awk -F"=" '{print $NF}' |
All times are GMT -5. The time now is 12:57 AM. |