cat file_list | [script to print last some characters]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat file_list | [script to print last some characters]
# 1  
Old 08-25-2009
cat file_list | [script to print last some characters]

Hello guys,

I have a list of files. For example:

Code:
/disk1/mediator_home/tmp/ntest/TSFILE00.8256.GGG1-U.0908250009.unp.20090824P8.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8257.GGG1-U.0908250013.unp.20090825P1.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8257.GGG1-U.0908250013.unp.20090824P8.ic
/disk1/mediator_home/tmp/ntest/TSFILE00.8256.GGG1-U.0908250009.unp.20061116P1.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8257.GGG1-U.0908250013.unp.20090825P1.ic
/disk1/mediator_home/tmp/ntest/TSFILE00.8256.GGG1-U.0908250009.unp.20321116P1.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8257.GGG1-U.0908250013.unp.20090824P8.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8257.GGG1-U.0908250013.unp.20061116P1.is
/disk1/mediator_home/tmp/ntest/TSFILE01.2009.08.23.00181910.unp.20090823P1.ic
/disk1/mediator_home/tmp/ntest/TSFILE01.2009.08.23.00111909.unp.20090823P1.ic
/disk1/mediator_home/tmp/ntest/TSFILE01.2009.08.23.00111909.unp.20090822P8.ic
/disk1/mediator_home/tmp/ntest/TSFILE00.8256.GGG1-U.0908250009.unp.20090825P1.is
/disk1/mediator_home/tmp/ntest/TSFILE00.8254.GGG1-U.0908250002.unp.20090824P8.is
/disk1/mediator_home/tmp/ntest/TSFILE01.2009.08.23.00051908.unp.20090822P8.ic
/disk1/mediator_home/tmp/ntest/TSFILE01.2009.08.23.00051908.unp.20090823P1.ic
/disk1/mediator_home/tmp/ntest/TSFILE00.8255.GGG1-U.0908250005.unp.20090824P8.is

I need to get list of unique characters from the last, like this:
substring (s, length(s) - 13, 10)

For example: above output is:

Code:
20061116P1
20090822P8
20090823P1
20090824P8
20090825P1
20321116P1

Please help,

Thanks in advance
# 2  
Old 08-25-2009
Code:
awk -F"." '{ if (NF>0) print $(NF - 1)  }' file | sort -u

# 3  
Old 08-25-2009
try this also...

awk -F"/" '{ print $6 }' test_file | sed 's/-/./g' | awk -F"." '{ print $7 }' | sort |uniq



20061116P1
20090822P8
20090823P1
20090824P8
20090825P1
20321116P1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print the first 7 characters of each column

Hello all, I have a data like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674- X:1662912 X:10181 X:16491 X:05506 X:05216- X:05488 X:46872 X:08471 X:04834 X:30170 The except result is like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674 X:16629 X:10181... (3 Replies)
Discussion started by: yhkoo
3 Replies

2. UNIX for Advanced & Expert Users

cat / sed process weird characters

Hi everyone, I'm trying to write a shell script that process a log file. The log format is generally: (8 digit hex of unix time),(system ID),(state)\n My shell script gets the file from the web, saves it in a local text directory. I then want to change the hex to decimal, convert from unix time... (7 Replies)
Discussion started by: bencpeters
7 Replies

3. Shell Programming and Scripting

Print N characters in ksh

Hi, I have this header on a script: echo "*************************************" How can I print 1000 "*" characters without to put them on the echo command? Understand? THIS IS AN EXAMPLE WHAT I NEED: print "1000 *" Or is possible to print or echo "*" characters until they... (8 Replies)
Discussion started by: iga3725
8 Replies

4. Shell Programming and Scripting

Use awk to print first 6 characters

Hi, i want to use awk to print the first 6 characters of a variable awk -F"|" '$3>0 { print $3 }' z00.unl > z001.unl but $3= 7 digits and i just want to print the first 6 digits. eg 1005779 but i want to print only 100577 (3 Replies)
Discussion started by: dealerso
3 Replies

5. Shell Programming and Scripting

Extra control characters being added when I create a file using cat command

Hi, I am using Cygwin.I created a new file and type into it using cat > newfile. When I open this using vi editor, it contains loads of extra control characters. Whats happening? (1 Reply)
Discussion started by: erora
1 Replies

6. Shell Programming and Scripting

Print the first four characters of hostname

Hey, I'm trying to print the first four characters of the hostname of a computer. I can get it from using: hostname -s | sed 's/...........$//'" but this is when I know how many characters are in the computer name. I dont understand why some like: hostname -s | sed '/..../p' wont... (7 Replies)
Discussion started by: yxian
7 Replies

7. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

9. Shell Programming and Scripting

print 10 characters in series

suppose fileA kanika123ABC 1222222222222222 raciat5678ty 1221123333331121 jessica78ulllo 2233243223333333 so output shud be print only first 10 characters in series and rest remain same kanika123A 1222222222222222 raciat5678 1221123333331121 jessica78u ... (1 Reply)
Discussion started by: cdfd123
1 Replies

10. Shell Programming and Scripting

Print the characters in a word

Hi, How can I split the characters in a word? For Eg: If my input is: command my output should be: c o m m a n d Please help me in doing it so. (5 Replies)
Discussion started by: chella
5 Replies
Login or Register to Ask a Question