sed, grep, cut or combine?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed, grep, cut or combine?
# 1  
Old 01-09-2007
sed, grep, cut or combine?

I am a beginner at shell scripting, actually i am working on my first script right now.
Anyway i have searched the world how to grep two letters from each word (it will always just be two words).

For example:
Example Blablabla

I want my script to cut out Ex (from the first word) and Bl (from the second word).
Which combined ExBl
However it will always be diffrent kind of words so i cannot use sed /Ex/ or something.
I also want Ex and Bl to be variables so i can use them later on.
# 2  
Old 01-09-2007

could this be the answer:
cut -c1-2 filename | cut f2" "-c1-2 filename

Very insecure of the second cut, f2 one.
However if this is the solution i still need them to become variables somehow or maybe by: a=cut -c1-2 filename
# 3  
Old 01-09-2007
One way...
$ echo abcdef QWERTY | sed 's/\(..\).* \(..\).*/\1\2/'

# 4  
Old 01-09-2007
$ echo abcdef QWERTY | awk '{print substr($1,1,2) substr($2,1,2)}'

# 5  
Old 01-10-2007
another way

Thanks for all answers, it helped alot.

Also just came up with another solotion could maybe come to hand as other users can read this thread as for help.
Its not compiled but it is a solotion which also works.

a=cut -c1-2 filename | sed "delete whole first line" | b=cut -c1-2 filename
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print/cut/grep/sed/ date yyyymmdd on the filename only.

I have this filename "RBD_EXTRACT_a3468_d20131118.tar.gz" and I would like print out the "yyyymmdd" only. I use this command below, but if different command like cut or print....etc. Thanks ls RBD_EXTRACT* | sed 's/.*\(........\).tar.gz$/\1/' > test.txt (9 Replies)
Discussion started by: dotran
9 Replies

2. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

3. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

4. UNIX for Dummies Questions & Answers

combine -A and -v in grep

I have a data file that looks like this: infile: A 13 Z 23 F 22 Z 413 R 16how do I combine the -A option with the -v option to get the lines that don't match 'Z' and their next lines? the outfile should be: A 13 F 22 R 16I tried: (1 Reply)
Discussion started by: jdhahbi
1 Replies

5. Shell Programming and Scripting

combine two grep statements

Hi I am wondering is it possible to combine two greps together I have two greps. grep "^,, *\." file (grep the line which has a '.' in the third column) grep "=" file (grep the line which has = anywhere) How to put them together so that if the content of the file that match either... (1 Reply)
Discussion started by: tiger66
1 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 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

8. Shell Programming and Scripting

grep this no. 0100025144 and combine

<CRMSUB:MSIN=0100025144,BSNBC=TELEPHON-9814072360-TS11&TS21&TS22,NDC=9814 <ENTROPRSERV:MSIN=0100025144,OPRSERV=UCSI,UCSI=771-919814047117&775-919814047117; <ENTRGCSERV:MSIN=0100025144,GCSERV=CALLWAIT-PROV&CALLHOLD&CLIP&HOTBILL&NATSS05,CLIPOVR=NO;... (3 Replies)
Discussion started by: dodasajan
3 Replies

9. Shell Programming and Scripting

cut sed grep or other?

Hi Is there a way to cut the last two characters off a word or number given that this word or number can be of varying length? I have tried something like TEST=`echo $OLD | cut -c 1-5` where $OLD is a variable containing a number like 1234567 which gives a result of 12345. This is fine... (4 Replies)
Discussion started by: rleebife
4 Replies

10. UNIX for Dummies Questions & Answers

sed or grep or perl combine two lines

how do i search for the phrase "expected" on line one and "received" on line two. (there is a newline in between the two) I would like to know if/how this can be done in perl and/or grep and/or sed (3 Replies)
Discussion started by: artjaniger
3 Replies
Login or Register to Ask a Question

Featured Tech Videos