printing last two characters of each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing last two characters of each line
# 1  
Old 01-07-2009
printing last two characters of each line

Hello,
any trick to print line number and last two characters of each line ?
# 2  
Old 01-07-2009
Hi,

this command prints the line number, a colon, a space and the last two characters for each line:
Code:
awk '{ print NR ": " substr($0, length($0)-1) }' test.txt

# 3  
Old 01-07-2009
Code:
echo 'aslkjd' | sed -e 's/.*\(..\)/\1/;=' | sed '/./N;s/\n/ /'

# 4  
Old 01-07-2009
awk ' NF > 0 ' test.txt >tmp.txt : remove the blank lines
awk '{ print NR ": " substr($0, length($0)-1) }' tmp.txt
# 5  
Old 01-07-2009
thanks Smilie

found this too very good info http://student.northpark.edu/pemente/awk/awk1line.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Remove non printing characters from file

How do I remove the printer escape sequence, the first 5 characters, that occurs on every 33rd line in a file, see hex dump of line 1. 0000 1e 00 00 00 00 0a 0a 0a 20 0a 20 20 20 20 20 20 .... 0010 20 20 20 20 20 20 20 20 20 20 0a 42 49 4c 4c 20 Thanks, (2 Replies)
Discussion started by: jgt
2 Replies

3. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

4. Shell Programming and Scripting

Maybe by AWK: printing help diagonal matrix characters into line

Hi Experts, I want to print this charts diagonal data into straight lines. This is a matrix 24X24 Horizontal and vertical. - I want to print all the diagonal cutting characters into straight line: Data: E F S S A H A L L A T M C N O T S O B O D U Q H I W I B N L O C N I L N L A N S I N... (9 Replies)
Discussion started by: rveri
9 Replies

5. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

6. Linux

Removing non printing characters from a csv file

Hi, I have an csv file and there are some non printable characters(extended ascii) so I am trying to create a clean copy of the csv file . I am using this command: tr -cd "" < /opt/informatica/PowerCenter8.6.0/server/infa_shared/SrcFiles/ThirdParty/locations.csv > ... (4 Replies)
Discussion started by: gerkus
4 Replies

7. UNIX for Dummies Questions & Answers

printing password having special characters

Hi I have a password stored in a file (which is a user input) The password is having the special character $ say the password is pw$ord and is stored in the file pw_note I am using the following statement to store the passowrd in a variable $schema_pwd = `cat $dir/pwd_note` ; Now if i print... (4 Replies)
Discussion started by: ssuresh1999
4 Replies

8. UNIX for Dummies Questions & Answers

Printing 5 raw characters to a printer

Hi there, I want to open a cash drawer remotely. The cash drawer is commanded by a printer. I need to connect to the cash drawer which is connected over a network (and shared) and simply send a sequence of five ASCII commands (see http://pages.prodigy.net/daleharris/popopen2.htm) to a... (5 Replies)
Discussion started by: Friğrik
5 Replies

9. Shell Programming and Scripting

vi : inserting non-printing characters

I am trying to edit a syslinux msg file. I want to precede color codes with control characters. I have tried insert mode, then control v followed by the color code; however, I continue to get " [O " if I type the color code or enter ESC mode. How can I just insert say " ^L " ? (2 Replies)
Discussion started by: cstovall
2 Replies

10. UNIX for Dummies Questions & Answers

printing control characters

using c-shell, does anyone know how to send control characters to the printer before the job? I need to set a printer to print in condensed mode HELP (1 Reply)
Discussion started by: mglinsk
1 Replies
Login or Register to Ask a Question