Display the last part of a number list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display the last part of a number list
# 1  
Old 06-26-2016
Display the last part of a number list

Hi ,
i have a file wich have 50+ of numbers like :

Code:
  
0.014544106
0.005464263
0.014526045
0.005484374
0.014539412
0.005467600
0.014558349
0.005452185

i would like to display the list from the 6th bit to the end for example

0.005452185 (should become) 2185.

I've tried with tail -c 4 filename but it display just the last one in the file.

Thanks!

Regards
# 2  
Old 06-26-2016
Would this work?

Code:
grep -o '....$' Board27.numbers

# 3  
Old 06-26-2016
If your system's grep utility does not support the -o option, you could also do this entirely in the shell (with any shell that performs basic POSIX-required parameter expansions) using:
Code:
while read -r line
do	printf '%s\n' "${line#${line%????}}"
done < file

which with your sample input file produces the output:
Code:
4106
4263
6045
4374
9412
7600
8349
2185

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 06-27-2016
How about the "Substring Parameter Expansion" (possibly not available in all POSIX compliant shells):

man bash:
Quote:
${parameterSmilieffset}...
If offset evaluates to a number less than zero, the value is used as an offset in characters from the end of the value of parameter.

Code:
printf '%s\n' "${line: -4}"

# 5  
Old 06-27-2016
Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

2. AIX

(ASK) Part number

hii master Unix I finish find to google how to command for the show part number and asset number at a IBM P series and i notyet finded. maybe all master unix can help me about what the command part number and asset number at server IBM P series. regards, amin (1 Reply)
Discussion started by: williamen
1 Replies

3. Shell Programming and Scripting

Extract number part from the string in ksh 88

I have to extract number part (Date and timestamp part ) from the following 3 strings AB_XYZA_20130930183017.log AB_DY_XYZA_20130930183017.log AB_GZU_20130930183017.log Output should be 20130930183017 Please help me to get the string like above Thanks (2 Replies)
Discussion started by: smile689
2 Replies

4. Shell Programming and Scripting

To display the selected part in text file of unix

0400903071220312 20120322 20:21 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS 182644 000C2 8122011 0000 000 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS ... (6 Replies)
Discussion started by: rammm
6 Replies

5. UNIX for Advanced & Expert Users

how to fetch part of a line and display

Input of data: Student: Hari Roll No: 24777 Phone No: 122334 Student: Sudha Roll No: 247911 Phone No: 34552111 Student: Lata Roll No: 247790 Phone No: 7675656554 Student: Kutty Roll No: 24677 Phone No: 12442334 Student: Sudhar Roll No: 247411 Phone No: 3455244111 ... (4 Replies)
Discussion started by: rampriya.s
4 Replies

6. Solaris

part number for netra 440 dvd w

Hi i am accessing the server remotly. i want to replace bad dvd writer. how do i know the part number of the dvd drive for raising a spare. thanks (3 Replies)
Discussion started by: sunnybee
3 Replies

7. Shell Programming and Scripting

decrement a four part number in shell script

I have a four part number eg: 1.21.1.3 I need to find a way in shell script to decrement this by one and put in a loop so the values printed will be 1.21.1.2 1.21.1.1 1.21.1.0 Which is the best way to do this in shell script?? (7 Replies)
Discussion started by: codeman007
7 Replies

8. UNIX for Dummies Questions & Answers

row count but only number part

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

9. UNIX for Dummies Questions & Answers

getting memory part number

Hello everbody: another dummy question. I have SOL9, is there any command I can get the part number of the installed memory kit on the system, I tried prtdiag but it doesnt display that. Thanks alot (0 Replies)
Discussion started by: aladdin
0 Replies

10. UNIX for Dummies Questions & Answers

display full unix path as part of the command line

Hi all, Does anyone know how to ammend the .cshrc file in $HOME for your session to display the path as part of the command line? So that I dont need to keep on typing pwd to see where I am? thanks Ocelot (3 Replies)
Discussion started by: ocelot
3 Replies
Login or Register to Ask a Question