List all file whose 3rd char is digit


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers List all file whose 3rd char is digit
# 1  
Old 05-14-2019
List all file whose 3rd char is digit

list all file whose 3rd char is digit (or Nth position is digit)

what will be the required command?
# 2  
Old 05-14-2019
Code:
ls ??[0-9]*

These 2 Users Gave Thanks to Corona688 For This Post:
# 3  
Old 05-14-2019
With an ERE (egrep or grep -E)
Code:
ls | egrep '^.{2}[0-9]'

^ beginning of line
.{2} a character 2 times
[0-9] a character in the range 0-9

Within " " the shell substitutes $var or ${var} by its value, before it hands it to the egrep
Code:
num=2
ls | egrep "^.{$num}[0-9]"


Last edited by MadeInGermany; 05-15-2019 at 05:12 AM.. Reason: Added a missing dot (thanks RudiC)
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 05-14-2019
Slightly different approach:

Code:
echo ??[0-9]* | tr " " "\n"

This User Gave Thanks to wisecracker For This Post:
# 5  
Old 05-14-2019
Code:
compgen -f -X '!??[0-9]*'

# 6  
Old 05-15-2019
The simple "arguments to lines" command is printf
Code:
printf "%s\n" ??[0-9]*

But commands can overflow with "too many arguments".
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

I need to find in a file a list of number where last two digit end in a range

I all I am tryng to find a way to sort a list of number in a file by the value of last two digit. i have a list like this 313202320388 333202171199 373202164587 393202143736 323202132208 353201918107 343201887399 363201810249 333201805043 353201791691 (7 Replies)
Discussion started by: rattoeur
7 Replies

2. Shell Programming and Scripting

Moving alphanumeric files according to the digit in file name

This is the content of my directory c_g_se1_gb.ph c_g_se1_gb.ph_pl_s.t c_g_se1_gb.ph_pl_tr.t c_g_se3_gb.ph c_g_se3_gb.ph_pl_s.t c_g_se3_gb.ph_pl_tr.t c_g_se2_gb.ph c_g_se2_gb.ph_pl_s.t c_g_se2_gb.ph_pl_tr.t c_g_se4_gb-1.ph c_g_se4_gb-1.ph_pl_s.t c_g_se4_gb-1.ph_pl_tr.t... (9 Replies)
Discussion started by: sammy777888
9 Replies

3. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

4. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

5. UNIX for Dummies Questions & Answers

list all files containing 4 digit number using grep

how can i list all files in my home directory that have a 4 digit id number, the line number where the id is located and the id itself not printing the entire line? (5 Replies)
Discussion started by: hobiwhenuknowme
5 Replies

6. Shell Programming and Scripting

AWK: list files with 1rst col=N and char position 123=N

I need to list all files where 1rst column=ABK and char position 123 to 125=ZBK: For the first part I can I can do a awk '{$1="ABK";print}' file and for the second a cut -c123-125 file | grep ZBK but this would only work partially.. How can I do this with only one awk command ? Thanks in... (10 Replies)
Discussion started by: cabrao
10 Replies

7. Shell Programming and Scripting

list all file whose 2nd char is digit!

how to list all files in current directory whose second character is a digit. i guess i hav to use grep command + ls for this. but dont know how to use? (6 Replies)
Discussion started by: Sgupta
6 Replies

8. UNIX for Dummies Questions & Answers

Replacing digit with characters in a file

Hi, I have a file with 40 columns out of which 15 are amount fields. There are approximately 6 mn records in this file. The file has data in following format: 123A,Ank,00.468,US,IL,780,53489 253A,Tng,-00.456,US,CA,452,46781 363A,nkk,-00.023,US,NJ,539,09625 I need to take all amount fields... (1 Reply)
Discussion started by: wahi80
1 Replies

9. Shell Programming and Scripting

How to convert a 2 digit to 4 digit

Hi All, How can i convert a number 24 to 0024 In the same way how can i convert 123 to 0123? All this has to be done inside a script Thanks in advance JS (6 Replies)
Discussion started by: jisha
6 Replies

10. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies
Login or Register to Ask a Question