Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to search for a file having a particular character in a particular place in a directory.? Post 302881062 by RavinderSingh13 on Thursday 26th of December 2013 10:38:43 AM
Old 12-26-2013
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a non zero character in file

Hi, I have a log file which has entries as Staged 0 records from fn.dat (0 failed) 01/01 01:01:01 I 0 Error Transactions I want to find out any line that has an entry like "(1 failed)" or "(2 failed)" or any number in general ( >0 ) similarly it should search for string like "1... (4 Replies)
Discussion started by: misenkiser
4 Replies

2. Shell Programming and Scripting

Insert a special character $ in place of extra spaces

Hi Experts, I have called some.txt with the following content. oracle HYRDSRVIHUB01 pts/0 TESTIHUB 07-JUN-10 CREATE TABLE TESTIHUB PHONE ... (12 Replies)
Discussion started by: naree
12 Replies

3. UNIX for Dummies Questions & Answers

how to search and list file with wildcard character

hi, I want to search all files in the current working direcotry and to print in comma (,) seperated output. But I have two patterns to search for. Files will be in ABC20100508.DAT format. Search should happen on the format (ABC????????.DAT) along with date(20100508). I can do a ls... (2 Replies)
Discussion started by: anandapani
2 Replies

4. UNIX for Dummies Questions & Answers

using gsed with cp to sort files in directory - every N file copy to new place

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... (4 Replies)
Discussion started by: dgoss
4 Replies

5. Shell Programming and Scripting

perl script to search n place a pattern

hi, i have one file as t1.txt as below hi hello welcome i want perl script to search for the pattern "abcd" in the file. if the pattern doesn't exist, i want to insert that pattern at the end of the same file t1.txt my o/p should be hi hllo welcome abcd thank you (3 Replies)
Discussion started by: roopa
3 Replies

6. Shell Programming and Scripting

Place , character after 3 digits from left to right in a string

Hi All, Could anyone please help me, how to put ‘,' character after 3 digits from right to left count,among 17 digits sting. unix scripting Example - I am having 12345678911234567 digits Accepted result-- 12,345,678,911,234,567 Note- 12345678911234567 digits will be dynamic at run time, I... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

7. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

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 ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

8. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

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. (2 Replies)
Discussion started by: saurau
2 Replies

9. UNIX for Advanced & Expert Users

Replace certain character at specific place with related character

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... (1 Reply)
Discussion started by: dell1520
1 Replies

10. Shell Programming and Scripting

Search for a file in all directories and place the file in that directory

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... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies
LS(1)							      General Commands Manual							     LS(1)

NAME
ls, lc - list contents of directory SYNOPSIS
ls [ -dlmnpqrstuFQ ] name ... lc [ -dlmnpqrstuFQ ] name ... DESCRIPTION
For each directory argument, ls lists the contents of the directory; for each file argument, ls repeats its name and any other information requested. When no argument is given, the current directory is listed. By default, the output is sorted alphabetically by name. Lc is the same as ls, but sets the -p option and pipes the output through mc(1). There are a number of options: -d If argument is a directory, list it, not its contents. -l List in long format, giving mode (see below), file system type (e.g., for devices, the # code letter that names it; see intro(3)), the instance or subdevice number, owner, group, size in bytes, and time of last modification for each file. -m List the name of the user who most recently modified the file. -n Don't sort the listing. -p Print only the final path element of each file name. -q List the qid (see stat(3)) of each file; the printed fields are in the order path, version, and type. -r Reverse the order of sort. -s Give size in Kbytes for each entry. -t Sort by time modified (latest first) instead of by name. -u Under -t sort by time of last access; under -l print time of last access. -F Add the character / after all directory names and the character * after all executable files. -L Print the character t before each file if it has the temporary flag set, and - otherwise. -Q By default, printed file names are quoted if they contain characters special to rc(1). The -Q flag disables this behavior. The mode printed under the -l option contains 11 characters, interpreted as follows: the first character is d if the entry is a directory; a if the entry is an append-only file; D if the entry is a Unix device; L if the entry is a symbolic link; P if the entry is a named pipe; S if the entry is a socket; - if the entry is a plain file. The next letter is l if the file is exclusive access (one writer or reader at a time). The last 9 characters are interpreted as three sets of three bits each. The first set refers to owner permissions; the next to permissions to others in the same user-group; and the last to all others. Within each set the three characters indicate permission respectively to read, to write, or to execute the file as a program. For a directory, `execute' permission is interpreted to mean permission to search the directory for a specified file. The permissions are indicated as follows: r if the file is readable; w if the file is writable; x if the file is executable; - if none of the above permissions is granted. SOURCE
/src/cmd/ls.c /bin/lc SEE ALSO
stat(3), mc(1) LS(1)
All times are GMT -4. The time now is 10:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy