Searching files in a directory.Urgent


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching files in a directory.Urgent
# 8  
Old 12-12-2005
Quote:
Originally Posted by srivsn
Hi Mona,

Thx a lot. It worked. Smilie Can you tell me how to split a large file when it came across a pattern like "###" in the beginning of the line.
Eg: ### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16

I have multiple lines like the one above in a single file. I have to split the file into number of files when I came across ### at the beginning of the line and store the lines including the ### line in a temporary file. Please help.

Thx in advance........
srivsn
I don't think this can be done with a single command. Perhaps i wrote a shell script for this. The file to be splited should be given as argument.

Code:
file=0
tot_line=`wc -l $1 | awk '{print $1}'`
i=1
rm "$1_"*
while [[ i -le tot_line ]]
do
line=`tail +"$i" $1 | head -1`
echo $line | grep '^###' > /dev/null
if [[ $? == 0 ]]
then
(( file = file + 1 ))
fi
echo $line >> "$1_"$file
(( i = i + 1 ))
done

Code:
/mona> cat RPT_1dfsdf

Code:
ffsdfsdf
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
ffsdfsdf
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
dfsdfsd
sdfsdf
sdfsdf
sdfsfd
ffsdfsdf
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
/mona>split_file.sh RPT_1dfsdf
/mona>ls -lt | head
-rw-r--r--   1 test     test         105 Dec 12 12:42 RPT_1dfsdf_2
-rw-r--r--   1 test     test          67 Dec 12 12:42 RPT_1dfsdf_3
-rw-r--r--   1 test     test           9 Dec 12 12:42 RPT_1dfsdf_0
-rw-r--r--   1 test     test          76 Dec 12 12:42 RPT_1dfsdf_1
/mona>cat RPT_1dfsdf_0
ffsdfsdf
/mona>cat RPT_1dfsdf_1
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
ffsdfsdf
/mona>cat RPT_1dfsdf_2
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
dfsdfsd
sdfsdf
sdfsdf
sdfsfd
ffsdfsdf
/mona>cat RPT_1dfsdf_3
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies

2. UNIX for Beginners Questions & Answers

Searching the value of a specific attribute among xmls files from a particular directory location

Hi Folks , I have the different xml files at the following directory `/opt/app/rty/servers/tr/current/ops/config` Let's say there are three files named abc.xml bv.xml ert.xml Now inside these xml there can be many tags as like shown below <bean id="sdrt"... (6 Replies)
Discussion started by: unclesamm
6 Replies

3. Shell Programming and Scripting

Find/searching files in subdirectories excluding the fiels in Parent Directory

Hi All, requirement is to find and remove the files from sub directories but it should exclude the files from parent directory. At present i am using the below one but it finds and remove files from both parent and sub directories. find ${PATH} -type f \( -name securitas\* -o -name \*gz... (1 Reply)
Discussion started by: Naveenkk
1 Replies

4. Shell Programming and Scripting

recursive searching for files in directory that matches a particular name - taking care of links

Hi, I am writing a shell script that finds all files named <myFile> in a directory <dir> or any of its subdirectories, recursively. I also need to take care of symbolic links that may form cycles, to avoid infinite loops. I started writing the code but got stuck. I thought using recursion... (7 Replies)
Discussion started by: vickylife
7 Replies

5. Shell Programming and Scripting

Help needed with searching files and moving them to a different directory

I am new to shell scripting. Can someone help me out with this one please? I need to write a script fot the following scenario: I am currently in /parent directory. I have a set of files in /parent/error_files directory My script has to search for a file in /parent/erratic_files... (1 Reply)
Discussion started by: ss3944
1 Replies

6. Solaris

Searching for files in a Directory

Hi, I am trying to write a script that will search in a particular directory and tell me how many files are in there. I then want to be able to email certain users of how many files are in that directory and what the file names are? any help would be great as i am getting confused. thanks (3 Replies)
Discussion started by: Pablo_beezo
3 Replies

7. UNIX for Dummies Questions & Answers

searching files inside directory

hey, i need to use grep to search a bunch of header files inside a directory to return which file i can find the function i'm searching for in. how do i use wild cards to search through the files? i can only figure out how to search inside the directory, not inside the files that are in the... (4 Replies)
Discussion started by: kylethesir
4 Replies

8. Shell Programming and Scripting

searching files through all subdirectories beneath the current directory

i want to make a bash script that searches a specific pattern in files through all subdirectories beneath the current directory..without using the command grep-R but only the command grep.. e.g for i in * do grep "pattern" $i ..... ... done using the character (*) the script... (5 Replies)
Discussion started by: milagros
5 Replies

9. Shell Programming and Scripting

Searching for files over 30 days old in current directory

May be a simple question for experts here.... I need to get the list of files older than 30 days in the current folder. I tried "find", but it searches recursively in all the sub directories. Can I restrict the recursive search and extract the files only from current directory ? (18 Replies)
Discussion started by: cxredd4
18 Replies
Login or Register to Ask a Question