cut vs. sed vs. awk ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cut vs. sed vs. awk ?
# 1  
Old 09-28-2004
Question cut vs. sed vs. awk ?

hi again...need new help guysSmilie

the file contains following infos...

users/abc/bla1.exe
newusers/defgh/ik/albg2.exe
users2/opww/ertz/qqwertzu/rwerwew.exe

how to get the file content into...

users/abc/
newusers/defgh/ik/
users2/opww/ertz/qqwertzu/

with...

[sed -e ´s/.exe/ /g´<infile>outfile]

you can erase the point and the extension

by the way, when you make

[sed -e ´s/.....exe/ /g´<infile>outfile]

you can also delete chars, but then it would be like..

users/abc/
newusers/defgh/ik/al
users2/opww/ertz/qqwertzu/rwe

anybody knows a trick? thx...

secondary I just don't know if there's another chance by using awk or cut.
# 2  
Old 09-28-2004
What about a little script like...

Code:
#!/bin/bash

while read line
do    
   path=${line%/*}  
   echo $path
done < infile > outfile

exit 0

Cheers
ZB
# 3  
Old 09-28-2004
MySQL nice !

works fine, thx....

some problems like..

script interpreter "/bin/bash" not found
script interpreter link resolves to "/usr/bin/bash"

..but with #!/bin/sh it works perfectly on my systemSmilie

by the way I'm litte confused by the different shells...
# 4  
Old 09-28-2004
Yep, that's just because my "bash" is in a different place to yours. You can change the shebang to #!/usr/bin/bash and it should work okay.

Cheers
ZB
# 5  
Old 09-28-2004
Lightbulb

could you pleaz interpret what the line

path=${line%/*}

does exactly?

the loop is nearly traceable and per "$" it gets the info from the file and so on..I know.

but what about the syntax {line%/*} ? it's not really clear. why it cuts exactly at the right position ? thx..
# 6  
Old 09-28-2004
From man bash
Quote:
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname
expansion. If the pattern matches a trailing portion of the
expanded value of parameter, then the result of the expansion is
the expanded value of parameter with the shortest matching pat-
tern (the ``%'' case) or the longest matching pattern (the
``%%'' case) deleted. If parameter is @ or *, the pattern
removal operation is applied to each positional parameter in
turn, and the expansion is the resultant list. If parameter is
an array variable subscripted with @ or *, the pattern removal
operation is applied to each member of the array in turn, and
the expansion is the resultant list.
So basically, discard the shortest pattern matching "/*" (i.e. a forward slash followed by "anything") from the right hand side of the variables value, and return the rest.

Cheers
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

editing file with awk cut and sed

HI All, I am new to unix. I have a file would like to do some editing by using awk, cut and sed. Could anyone help? This file contain 100 lines. There are one line for example: 2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17... (2 Replies)
Discussion started by: mimilaw
2 Replies

2. Shell Programming and Scripting

Cut on last backslash on hyperlink string-sed/awk??

hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar Needs to get "rtyp-2.5.6.jar" i.e character after last backslash "/" how to do this using sed/awk?? help is highly appreciated. (7 Replies)
Discussion started by: kkscm
7 Replies

3. Shell Programming and Scripting

cut, sed, awk too slow to retrieve line - other options?

Hi, I have a script that, basically, has two input files of this type: file1 key1=value1_1_1 key2=value1_2_1 key4=value1_4_1 ... file2 key2=value2_2_1 key2=value2_2_2 key3=value2_3_1 key4=value2_4_1 ... My files are 10k lines big each (approx). The keys are strings that don't... (7 Replies)
Discussion started by: fzd
7 Replies

4. Shell Programming and Scripting

Line/Variable Editing for Awk sed Cut

Hello, i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG: please help a newbie. below is my code: WorkingDir=$1 FileName=`cut -d ',' -f... (2 Replies)
Discussion started by: limamichelle
2 Replies

5. Shell Programming and Scripting

Substring using cut/awk/sed

Hi Gurus,I have a seemingly simple problem but struggling with it.It is as follows : I/p string - ABCDEFGHIJ20100909.txt desired o/p - AB,DEF,20100909,ABCDEFGHIJ20100909.txt How to achieve it ?Thanks in advance. Please use code tags, thank you (20 Replies)
Discussion started by: sumoka
20 Replies

6. UNIX for Dummies Questions & Answers

Awk/sed solution for grep,cut

Hi, From the file "example" with lines like below, I need the int value associated with ENG , i.e, 123 SUB: ENG123, GROUP 1 SUB: HIS124, GROUP 1 .. .. Normally , i do grep ENG example | cut -d ' ' -f 2 | cut -c 4-6 Is it possible to do it in simpler way using awk/sed ? ... (5 Replies)
Discussion started by: priyam
5 Replies

7. Shell Programming and Scripting

Sed or awk cut all lines after word

Hi, sorry for newbie question :confused: can't find how to cut ? from 1000 2000 word some text1.... 100 200 300 word some text2.... 10 20 30 abc word some text3.... to some text1.... some text2.... some text3.... (7 Replies)
Discussion started by: Trump
7 Replies

8. Shell Programming and Scripting

Sed Awk Cut Grep Combination Help ?

I have been reading for a few hours trying to educate myself enough to accomplish this task, so please know I have performed some research. Unfortunately, I am not a *NIX scripting expert, or a coder. I come from a network background instead. SO, here is my desired outcome. I have some Cisco... (5 Replies)
Discussion started by: abbzer0
5 Replies

9. Shell Programming and Scripting

cut in sed/awk

Hi Can i have an example where i should be able to cut columns (like for eg cut -c 1-3) in sed or awk. Regards Dhana (12 Replies)
Discussion started by: dhanamurthy
12 Replies

10. Shell Programming and Scripting

awk,sed or cut problem

Good afternoon, Sir's, I would like to seek your assistance regarding on this matter. $cat file1 111 aaaa bbb aass aaa files file1 temp temp1 pix 222 11 22 1 33 44 desired output: aaaa bbb aass files file1 temp1 222 11 22 1 33 44 thanks (7 Replies)
Discussion started by: invinzin21
7 Replies
Login or Register to Ask a Question