Shell - Matching 3 letter file names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell - Matching 3 letter file names
# 1  
Old 12-30-2008
Shell - Matching 3 letter file names

Hi

I am running a shell script with bdf command and want to match all files with length 3 inside a specific partitions. How do i do that

say

for example if i want to list all files with length 3 in /home/jimmy partition,

bdf /home/jimmy

the output i need is

xyx
abc
yyy
amp


Thanks
# 2  
Old 12-30-2008
Code:
#!/bin/bash
for i in `ls $1`
do
if [ `echo -n $i|wc --char` -eq 3 ]
then
echo $i
fi
done

# 3  
Old 12-30-2008
bdf won't give you any info on the files inside that partition. Instead try
Code:
find /home/jimmy -name '???' -type -f -print

# 4  
Old 12-30-2008
Quote:
Originally Posted by PrasannaKS
for example if i want to list all files with length 3 in /home/jimmy partition,

bdf /home/jimmy

the output i need is

xyx
abc
yyy
amp

Code:
cd /home/jimmy
printf "%s\n" ???

# 5  
Old 12-30-2008
Quote:
Originally Posted by s93366
Code:
#!/bin/bash
for i in `ls $1`


Not only is ls unnecessary, but it will break the script if any filenames contain spaces.
Quote:
Code:
do
if [ `echo -n $i|wc --char` -eq 3 ]
then
echo $i
fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Long file names within shell script

I am downloading a zip file that contain files that are very long. I am trying to process them, but cannot. I can move the files from one directory to another at the shell prompt, but not within a shell script, I get a stat error. The files look somewhat like this; ... (5 Replies)
Discussion started by: trolley
5 Replies

2. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

4. Shell Programming and Scripting

Matching the header of a .CSV file with dynamic field names

I have a .CSV file (frequency - weekly) whose header contains the year-week value in two of the columns which keeps changing every week. For an instance please see below. Column1,Column2,Column3,Column4,Column5,Column6,Column7,Column8,Column9,Column10,Column11,Column12,Column13,201420... (4 Replies)
Discussion started by: dhruuv369
4 Replies

5. Shell Programming and Scripting

Get all File names starting with letter P

Hi, I have lets say 10 files , I need to process them one by one. So I need a command to get one file name at a time to process it into a variable Example Files P1111.dat P3344.dat S344.dat ... v_file_name = 'p111.dat' .. I will rename it to something after processing ... (1 Reply)
Discussion started by: prassu
1 Replies

6. Shell Programming and Scripting

matching names in 2 text files

I have 2 text files like ________________________________ Company Name:yada yada ADDRESS:some where, CITY,STATE CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3 LEAD:first_name.last_name ________________________________ & Data file2 ... (1 Reply)
Discussion started by: rider29
1 Replies

7. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Shell Programming and Scripting

matching a letter in a word

hi, if i have a string of letters and seperatly i have a single letter. how do i check whether that specific letter is in my string aswell? any ideas? (2 Replies)
Discussion started by: Furqan_79
2 Replies

9. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies

10. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question