Sponsored Content
Top Forums Shell Programming and Scripting Sort a file content with space Post 302893052 by Akshay Hegde on Monday 17th of March 2014 07:32:37 AM
Old 03-17-2014
Code:
akshay@Aix:/tmp$ cat file
03/17/2014  10:35 AM  618 Admin\vick       abc_ xyz1_bc12_20140312_c.xlsx
03/17/2014  10:35 AM  618 Admin\david     abc_xyz1_bc12_20140312_c.xls
03/17/2014  10:38 AM  618 Admin\samar    pqr_tbd1_bc12_20140312_c.doc
03/17/2014  10:34 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip
03/17/2014  10:39 AM  618 Admin\vick      abc_ xyz1_bc12_20140312_c.xlsx
03/17/2014  10:42 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip

akshay@Aix:/tmp$ awk  'match($0,/[^ ]* [^ ]*$/) && !x[substr($0,RSTART,RLENGTH)]++' file
03/17/2014  10:35 AM  618 Admin\vick       abc_ xyz1_bc12_20140312_c.xlsx
03/17/2014  10:35 AM  618 Admin\david     abc_xyz1_bc12_20140312_c.xls
03/17/2014  10:38 AM  618 Admin\samar    pqr_tbd1_bc12_20140312_c.doc
03/17/2014  10:34 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip

I think Ravinder you did not notice input properly

see below carefully

Code:
akshay@Aix:/tmp$ cat f
03/17/2014  10:35 AM  618 Admin\vick       abc_ xyz2_bc12_20140312_c.xlsx
03/17/2014  10:35 AM  618 Admin\david     abc_xyz1_bc12_20140312_c.xls
03/17/2014  10:38 AM  618 Admin\samar    pqr_tbd1_bc12_20140312_c.doc
03/17/2014  10:34 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip
03/17/2014  10:39 AM  618 Admin\vick      abc_ xyz1_bc12_20140312_c.xlsx
03/17/2014  10:42 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip

akshay@Aix:/tmp$ awk '!a[$6]++' f
03/17/2014  10:35 AM  618 Admin\vick       abc_ xyz2_bc12_20140312_c.xlsx
03/17/2014  10:35 AM  618 Admin\david     abc_xyz1_bc12_20140312_c.xls
03/17/2014  10:38 AM  618 Admin\samar    pqr_tbd1_bc12_20140312_c.doc
03/17/2014  10:34 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip

akshay@Aix:/tmp$ awk  'match($0,/[^ ]* [^ ]*$/) && !x[substr($0,RSTART,RLENGTH)]++' f
03/17/2014  10:35 AM  618 Admin\vick       abc_ xyz2_bc12_20140312_c.xlsx
03/17/2014  10:35 AM  618 Admin\david     abc_xyz1_bc12_20140312_c.xls
03/17/2014  10:38 AM  618 Admin\samar    pqr_tbd1_bc12_20140312_c.doc
03/17/2014  10:34 AM  618 Admin\titlis      pqr_tbd1_bc12_20140312_c.zip
03/17/2014  10:39 AM  618 Admin\vick      abc_ xyz1_bc12_20140312_c.xlsx

akshay@Aix:/tmp$ awk  '{match($0,/[^ ]* [^ ]*$/);print substr($0,RSTART,RLENGTH)}' f
abc_ xyz2_bc12_20140312_c.xlsx
 abc_xyz1_bc12_20140312_c.xls
 pqr_tbd1_bc12_20140312_c.doc
 pqr_tbd1_bc12_20140312_c.zip
abc_ xyz1_bc12_20140312_c.xlsx
 pqr_tbd1_bc12_20140312_c.zip

akshay@Aix:/tmp$ awk '{print $6}' f
abc_
abc_xyz1_bc12_20140312_c.xls
pqr_tbd1_bc12_20140312_c.doc
pqr_tbd1_bc12_20140312_c.zip
abc_
pqr_tbd1_bc12_20140312_c.zip


Last edited by Akshay Hegde; 03-17-2014 at 08:44 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove space from file content

i am a bit new to shell scripting i have a file containing xxxx xx xx but i want to output the content as xxxxxxxx. thus removing the space. any idea how i can do this (4 Replies)
Discussion started by: blackzinga
4 Replies

2. UNIX for Dummies Questions & Answers

sort and find duplicates for files with no white space

example data 5666700842511TAfmoham03151008075205999900000001000001000++ 5666700843130MAfmoham03151008142606056667008390315100005001 6666666663130MAfmoham03151008142606056667008390315100005001 I'd like to sort on position 10-14 where the characters are eq "130MA". Then based on positions... (0 Replies)
Discussion started by: mmarshall
0 Replies

3. Shell Programming and Scripting

Sort content of text file based on date?

I now have a 230,000+ lines long text file formatted in segments like this: Is there a way to sort this file to have everything in chronological order, based on the date and time in the text? In this example, I would like the result to be: (19 Replies)
Discussion started by: KidCactus
19 Replies

4. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

5. Shell Programming and Scripting

Grep empty space and sort

Hi Expert, Kindly request for your expertise in this matter. I have below output: 12.125.124.173,xx1.common.com 12.125.124.174,xx2.common.com 12.125.124.175,xx3.common.com 12.125.124.176, 12.125.124.177, 12.125.124.178, 12.125.124.179,xx4.common.com 12.125.124.180,xx5.common.com... (8 Replies)
Discussion started by: regmaster
8 Replies

6. Shell Programming and Scripting

Sort a file content using one column

Hello All, I have a file which have content as below. 03/09/2014 10:35 AM 618 Admin\rick pqr_ klm2_pog12_20140309_c.xlsx 03/10/2014 10:35 AM 618 user\test01 mplz_ fgh2_lal12_20140310_c.xlsx 03/17/2014 10:35 AM 618 Admin\vick abc_ xyz2_bc12_20140317_c.xlsx 03/18/2014 ... (2 Replies)
Discussion started by: kumar30213
2 Replies

7. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. Shell Programming and Scripting

Replace file name with Space as content

Hi, I am having a files in my directory like this: 2014 1049_file1.txt 2014 1050_file2.txt 2014 1110_file3.txt 2014 1145_file4.txt 2014 2049_file5.txt I need to replace the above file names like this without changing the content of filename: file1.txt file2.txt file3.txt... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

9. UNIX for Dummies Questions & Answers

How to sort a content of a text file using a shell script?

I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting. I've attached the 'Input file' and the 'expected output' to this thread. Details provided in the expected output file will provide details on how the sort needs to be done. ... (16 Replies)
Discussion started by: nkarthik_mnnit
16 Replies

10. Shell Programming and Scripting

How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test "state" : "Disconnected",, "Rno" : "5554f1d2" "state" : "Disconnected",, "Rno" : "10587563" "state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 10:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy