cut last 4 chars


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut last 4 chars
# 1  
Old 06-28-2007
cut last 4 chars

hi

i wanted to cut last 4 chars from a text file

Input

A-B-C-V-15-0115
A-BL-CLE-T-VALUE-0125
M-T-L-G-0115
AT-PR-PE-CCT-0135

Output

0115
0125
0115
0135

I tried cut -f - -d "-" (thinking cut -f 5- -d"-" gives 5 ot end of line so only - should give last but floped)
# 2  
Old 06-28-2007
Code:
awk -F'-'  '{ print $NF} ' filename

# 3  
Old 06-28-2007
Quote:
Originally Posted by jim mcnamara
Code:
awk -F'-'  '{ print $NF} ' filename


thanks Jim... Thats was Simple...
# 4  
Old 06-28-2007
I could see a pattern there

so here's another one !

Code:
sed 's/^.*-//g' filename

# 5  
Old 06-28-2007
Code:
sed 's/.*\(....\)$/\1/' input_file

# 6  
Old 06-29-2007
Code:
while read str
do
	echo ${str##*-}
done < file

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

3. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

4. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

5. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

6. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question