Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


How to search for a file having a particular character in a particular place in a directory.?


 
Thread Tools Search this Thread
# 1  
How to search for a file having a particular character in a particular place in a directory.?

Hi Guys,

I want to search for a specific file in a directory which have a "b" letter as the 3rd character in the name of the file.

For Example :

Code:
/abc/efg/ldbjfblkj.sh
/abc/efg/erublkd.sh
/abc/efg/eibueora.sh
/abc/efg/kfvnmnb.sh

Since we have 2 files with "b" as a 3rd character in the name of the file. So, the result should give me this 2 files i.e

Code:
/abc/efg/ldbjfblkj.sh
/abc/efg/eibueora.sh

Additional Information : Operating system is Sun Solaris :5.10

Warm Regards,
Pramod

Last edited by bartus11; 12-26-2013 at 08:11 AM.. Reason: Please use code tags
# 4  
Hello,

Following code may help to find the requirement please.

Code:
$ ls -ltr | awk '{print $9}' | awk -vch="1" '{if(substr($0,3,ch) ~ "b") print $0}'

Output will be as follows.

Code:
cub_files_test_info
sub_digit_two_times
dobut

As we can see Output have all the files which have char b in their name at 3rd position.


Thanks,
R. Singh
# 5  
Ravinder,

There is no need to pipe ls output to an awk program. Wildcards ? and * can be used with ls command:
Code:
ls ??b*

# 6  
Thank you Yoda, I was thinking like if I will use grep
command with ls then it may get some other results too, so I have used awk.

But your given solution is working well and fine.Smilie


Thanks,
R. Singh
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Search for a file in all directories and place the file in that directory
ROCK_PLSQL
Hi All, Daily I am getting the updated file. I have to search for this file in all directories and sub directories. If the file existed in a particular directory then move this updated file to that particular directory. If the file is not existed in any of the directories then place this...... Shell Programming and Scripting
4
Shell Programming and Scripting
Replace certain character at specific place with related character
dell1520
hello i have file with 100k records and each one has certain value that starts at 28th column and certain value that starts at 88th column e.g. 1st file <25>1234567 ..... <88> 8573785485 i have aditional file with values which are related to value that starts at 88th column of the...... UNIX for Advanced & Expert Users
1
UNIX for Advanced & Expert Users
Change to directory and search some file in that directory in single command
saurau
I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help.... Shell Programming and Scripting
2
Shell Programming and Scripting
Script to search for a character in files in a Directory & remove it
rituparna_gupta
Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ...... Shell Programming and Scripting
6
Shell Programming and Scripting
using gsed with cp to sort files in directory - every N file copy to new place
dgoss
Hi all, I'm having a problem with some basic piping issues... I have been able to get in a directory and ls | gsed in order to list every N file for instance: ls | gsed -n '2~5p' The thing is I want to be able to copy the output files to a new directory. Basically directory /all has a...... UNIX for Dummies Questions & Answers
4
UNIX for Dummies Questions & Answers

Featured Tech Videos