2 problems... sed and sort


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 problems... sed and sort
# 1  
Old 03-08-2010
2 problems... sed and sort

Hi everyone!

I have a file like that:
Quote:
Jan:17:R00071
Jan:24:R00024
Jan:22:R00073
Jan:14:R00061
Jan:10:R00034
Feb:3:R00033
Feb:9:R00075
Feb:8:R00056
Feb:4:R00010
Feb:2:R00055
Feb:25:R00077
And I would it like that:
Quote:
Jan:10:R00034
Jan:14:R00061
Jan:17:R00071
Jan:22:R00073
Jan:24:R00024
Feb:2:R00055
Feb:3:R00033
Feb:4:R00010
Feb:8:R00056
Feb:9:R00075
Feb:25:R00077
I don't know how to keep the first field and sort the second one.



I have a second question with sed...
Quote:
VAR="toto"
cat file.txt| sed 's/^/$VAR:/g'
to put the variable $VAR at the beginning of the file...
But I have an output like this:

Quote:
$VAR:xxxx
$VAR:yyyy
$VAR:yyxxx
snork Smilie

I'm confused...

Thanks a lot for your answers
# 2  
Old 03-08-2010
For the first one...

Code:
sort -t: -k2 infile

For the second one...

Code:
sed 's/^/'$VAR':/g' infile

And useless use of cat...
# 3  
Old 03-08-2010
for 1st, one possible solution,

Code:
for Mon in Jan Feb Mar Apr Jun Jul Aug Sep Oct Nov Dec; do grep "$Mon" file | sort -n -t: -k2; done

Though, we can expect some better solution.

for second, use double quotes instead single.
# 4  
Old 03-08-2010
Smilie

Perfect guys!!!!

That's great


Thanks a lot! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

sed help with underscore problems

Hello, I have spent a couple of hours trying to answer this myself, so forgive me if the answer is simple but I have tried. I have a text file generated from svn log output which contains a list of files. Two regexps im using are * and * They both work but some lines has a mixture... (7 Replies)
Discussion started by: YogaBija
7 Replies

2. Shell Programming and Scripting

sed --> sort data by date

Hi, i "tried" to sort data by date. So far, i used sed to take the data from the last and the actual month. Now, after changing the year it is not working properly. i use: GNU bash, version 4.2.45(1)-release (x86_64-suse-linux-gnu) sed -n '/\//p' $Home/../scripte/pd_0.txt y is a... (6 Replies)
Discussion started by: IMPe
6 Replies

3. Shell Programming and Scripting

Sort with Awk, sed ....

I want to print out the lines that have the max value in column 3. and count the occurrence of column 1; if there are more than one occurrences, line with highest column 2 value will be printed. I have this data: input: AV 234 25 AV 256 76 AS 421 34 AV 124 76 BD 136 71 BD 241 76 AW... (10 Replies)
Discussion started by: aydj
10 Replies

4. UNIX for Advanced & Expert Users

problems with sed

$ echo "a,0,0,0,b,0" | sed 's/,0,/,1,/g' gives output as $ a,1,0,1,b,0 rather than as a,1,1,1,b,0 how can i solve this problem Thanks a lot in advance.... Use code tags. (4 Replies)
Discussion started by: manishma71
4 Replies

5. Shell Programming and Scripting

Help, awk sed sort

Hi,everyone: I'm new to shell, and now get trouble with some script: line=`/usr/xpg4/bin/awk '/^(*\|){2}'"$CR"'/ {print $0}' ${TIER4FILE}|grep -v OSNAME=`sed -n ''$LINE'p' $DATALOC/os` sort +1 /tmp/LhasaCRs2 > /tmp/LhasaCRs1 I cannot understand the "{2}" here. My mentor said it... (1 Reply)
Discussion started by: mycoy
1 Replies

6. Shell Programming and Scripting

Sed with sort doesnt work

Sed with sort doesnt work The below code doesnt work: sed -e '/^$/d' -e 's/,/|/g' | sort -t"|" -k1,1 -u file1 when i seperate them it work but i have to create intermediate file which i dont want to: sed -e '/^$/d' -e 's/,/|/g' file1 > file2 sort -t"|" -k1,1 -u file2 Help... (2 Replies)
Discussion started by: pinnacle
2 Replies

7. Shell Programming and Scripting

problems using sed

i have a file acc.sh which has about 10 lines and then i have defined $var which has a line number in it (say 5). i want to extarct from line 5 to the end of the file and put the output into another file. I have used sed -n $var,'$p' acc.sh | tee abc.sh but at times it does'nt work and gives an... (6 Replies)
Discussion started by: lassimanji
6 Replies

8. Shell Programming and Scripting

how to use sed to sort out this question

root:x:0:0:0000-Admin(0000):/:/sbin/sh rootcsh:x:0:1:0000-Admin(0000):/:/bin/csh nocol:x:6312:630:NOCOL Monitor,,,:/usr/local/lib/nocol-client:/usr/local/bin/bash nobody:x:60001:60001:uid no body:/:/usr/local/bin/bash noaccess:x:60002:60002:uid no access:/:/usr/local/bin/bash... (2 Replies)
Discussion started by: sonicstage
2 Replies

9. Shell Programming and Scripting

Problems with SED

I have a group of xml files and I need to insert 3 parameters just after this line in each file: ---------------Pattern to be searched for------------------------- <!--The following configuration is a test configuration--> ---------------Parameters to be added---------------------------... (11 Replies)
Discussion started by: collern2
11 Replies

10. UNIX for Dummies Questions & Answers

Problems with sed

Hi, I'm trying to use the sed command but I'm not sure how to use it properly. I've read the man pages for the sed command but I'm still unsure on how to use it. Basically I have a file with the words male and female written multiple times. I want to swap the word male for female and... (4 Replies)
Discussion started by: tugade
4 Replies
Login or Register to Ask a Question