Formatting help needed awk or sed maybe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting help needed awk or sed maybe
# 1  
Old 07-08-2010
Formatting help needed awk or sed maybe

I am executing the following command:
Code:
sort file1.txt | uniq -c | sort -n > file2.txt

The problem is that in file 2, I get leading spaces, Like so:
Code:
      1 N/A|A8MW11
      8 N/A|ufwo1
      9 N/A|a8mw11
     10 900003|smoketest297688
     10 N/A|a9dg4
     10 danny|danni
     12 900003|ufwo12
     12 N/A|a9po1
    106 00001|a8ar8

The whitespace after the first numbers are ok, because I will change that to a pipe, but is there a way to get rid of the leading white spaces first? Or is my command flawed?

Last edited by Scott; 07-08-2010 at 06:15 PM.. Reason: Please use code tags
# 2  
Old 07-08-2010
Code:
sort file1.txt | uniq -c | sort -n | perl -pe 's/^\s+//' > file2.txt

# 3  
Old 07-08-2010
Code:
sort file1.txt | uniq -c | sort -n | awk '$1=$1' > file2.txt

# 4  
Old 07-08-2010
Code:
awk '{a[$0]++}END {for (i in a) print a[i], i |"sort -n"}' file1.txt > file2.txt

# 5  
Old 07-09-2010
Quote:
Originally Posted by ddurden7
Code:
sort file1.txt | uniq -c | sort -n > file2.txt

Code:
sort file1.txt | uniq -c | sort -n | sed 's/^[ ]*//' > file2.txt

# 6  
Old 07-09-2010
Here is the solution that I used

Here is the solution that I used:

Code:
sort file1.txt | uniq -c | sort -n | sed 's/^[ ]*//' > file2.txt

Thanks all

Last edited by radoulov; 07-09-2010 at 11:52 AM.. Reason: Code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies

2. Shell Programming and Scripting

Help needed with file output awk sed command - please

Hi I have a file that contains lines starting with a particular string plus a Colon: I need to output all these lines but only what comes after the colon Can you pelase assist? Example of lines in the file: com.ubs.f35.cashequities/cashequities: 1 2 ... (5 Replies)
Discussion started by: mnassiri
5 Replies

3. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

4. Shell Programming and Scripting

Formatting Help needed(Sed)

I have a file called abc.txt which has following contents. 10.180.8.231=31608 10.180.8.232=29011 10.180.8.233=31606 10.180.8.234=40501 10.180.8.235=32591 10.180.8.236=31605 10.180.8.237=30561 10.180.8.238=14231 How would i find a ip address having maximum number of ram available. Here... (2 Replies)
Discussion started by: pinga123
2 Replies

5. Shell Programming and Scripting

formatting data file with awk or sed

Hi, I have a (quite large) data file which looks like: _____________ header part.. more header part.. x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 ... ... x59 x60 y1 y2 y3 y4... ... y100 ______________ where x1, x2,...,x60 and y1, y2,...y100 are numbers of 10 digits (so each line... (5 Replies)
Discussion started by: lego
5 Replies

6. Shell Programming and Scripting

awk or sed help needed

Hi All, p1=90; if then echo "<font color=red>" else echo "<font color=green>" fi how to i do it in awk or sed scripting ? (4 Replies)
Discussion started by: raghur77
4 Replies

7. Shell Programming and Scripting

sed or awk help needed

hi all, tnsping DBNAME > out.txt cat out.txt TNS Ping Utility for Linux: Version 10.2.0.2.0 - Production on 23-JUL-2009 05:49:52 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: /fisc/oracle/product/10.2.0/network/admin/sqlnet.ora Used TNSNAMES adapter to... (2 Replies)
Discussion started by: raghur77
2 Replies

8. Shell Programming and Scripting

sed or awk scripting help needed

hi all, for an example : df -k output shows: $ df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p6 3099260 1117760 1824068 8% / /dev/cciss/c0d0p1 256666 18065 225349 8% /boot none 8219180 0 8219180 0% /dev/shm /dev/mapper/vglocal-home 1032088 245172 734488 26%... (7 Replies)
Discussion started by: raghur77
7 Replies

9. Shell Programming and Scripting

Sed/Awk Help needed

Hello All, Does anybody know how to extract the entries from the 1st and second column that match a multiple regex expression using either sed or awk? I have a 40 k file with the data that looks like this. 2 VZudbEE.ds_HP11i-726..> 2 VZudbEEE.ds_IB-726-5..> 2... (1 Reply)
Discussion started by: liketheshell
1 Replies

10. Shell Programming and Scripting

AWK/SED Help needed

Hi, I'm new to Awk/Sed programming. I have a status file like this: TYPE | FILE1 | Now Started TYPE | FILE2 | Just Finished TYPE | FILE3 | Now Started TYPE | FILE4 | Just Finished For a given FILE no, I need to change the "Now Started" condition to "Just Finished" in this file. The... (5 Replies)
Discussion started by: autouser123
5 Replies
Login or Register to Ask a Question