Jump to a specific place in a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Jump to a specific place in a file?
# 1  
Old 07-11-2008
Jump to a specific place in a file?

If I cat a file
And want to go to the first instance of a particular value - what command would I use?
And then from that point where I jumped to search for another value - but only search from that point forward not before the file?

Thanks~
# 2  
Old 07-11-2008
Hammer & Screwdriver are you trying to do yourself, or as part of automated script function

To do yourself, use your editor, such as vi.
Code:
>vi filename
/particular    {would search for the word particular}
n         {would find the next occurrence}

Or, as part of a script would be potentially more involved. And would require a little more info on your intent.
Code:
> cat -n uprlwr.fmt | grep "VERSION"
    32  VERSION,4,C

That tells me that there is a reference to the word VERSION at the 32nd line in my file. By combining head and tail commands, I can extract a subset of my original file.
# 3  
Old 07-11-2008
Code:
pattern1="fox"
pattern2="dog"
awk -v pat1="$pattern1" -v pat2="$pattern2" \ 
           'BEGIN{ found==0}
         if(found==0)         
            {if(index($0, pat1)> 0) {found=NR} }
         if(found>0  && index($0, pat2)>0) {print $0} } ' inputfile


This code starts looking for "dog" only after it finds "fox".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to place specific contents filename within text file

I am trying to use awk to place the contens of a filename in $1 and $2 followed by the data in the text file. Basically, put the filename within the text file. There are over 1000 files in the directory and as of now each file is saved with a unique name but it is not within the file. Thank you... (10 Replies)
Discussion started by: cmccabe
10 Replies

2. Shell Programming and Scripting

Unable to get the Specific column with 2 decimal place

Hi, I have an issue converting decimal places of a particular column, i am using below script to get the output, but the output is not generating in desired format. awk -F"," 'BEGIN{OFS=","}{if(NR==0)getline;if ($7 != "") {if ($7 > 0) $7=$7/100 ; {printf "%.2f"... (3 Replies)
Discussion started by: rramkrishnas
3 Replies

3. Shell Programming and Scripting

How to merge variable data from another file into specific place?

Hello, I'm trying to create multiple commands using a variable input from another file but am not getting any successful results. Basically, file1.txt contains multiple lines with single words: <file1.txt> yellow blue black white I want to create multiple echo commands with these... (8 Replies)
Discussion started by: demmel
8 Replies

4. UNIX for Advanced & Expert Users

vimdiff jump to other file or switch windows

This took me quite awhile to find so I wanted to share this with other people. To switch windows in vimdiff or to navigate windows in vimdiff or to change windows in vimdiff try the following: The ":vertical" command can be inserted before another command that splits a window. ... (0 Replies)
Discussion started by: cokedude
0 Replies

5. Shell Programming and Scripting

place cursor in specific coordinates

Hi, I have this problem on how to place the cursor in a text editor (for example: pico). I made this script that would attach comments to a script file then open the script file, I would like to know how to place the cursor in a specific place, for example at the end of the comments, ... (1 Reply)
Discussion started by: lechelle
1 Replies

6. Shell Programming and Scripting

script for inserting line at specific place in file

I use zentyal for my server admin, which is great but zentyal auto-generates config file on boot and hence overwrites any changes made directly to config files. In order to allow multiple user access to a MS ACCESS database, I need to customise the smb.conf file and add the following line to the... (9 Replies)
Discussion started by: barrydocks
9 Replies

7. Shell Programming and Scripting

Read from file specific place in file using inode

Hello, I am using tcsh on AIX. I would like to write a script that does the following: 1. given an inode, how do I find exactly the name of the file? I know I could do this using ls -i | grep <inode> but it returns: <inode> <filename>. I need some string manipulation or something to... (1 Reply)
Discussion started by: lastZenMaster
1 Replies

8. Shell Programming and Scripting

[bash] jump from one txt file to another

Hi all, I need to create a bash script that reads a txt file on a remote (Windows 2003) server, gets the IP-addresses out of it and then fetches the folders to copy out of another txt file. (all files are auto-generated) The IP addresses that don't have a folder_list file should be ignored. At... (31 Replies)
Discussion started by: laurens
31 Replies

9. Shell Programming and Scripting

Splitting av file in 2 at specific place based on textpattern

I have a file that I want to split in 2 (with Bourne shell sh) preferably. The file consists of groups of lines separated by newline. The file can vary in length, so I need to check number of groups of text. Here's an example ====EXAMPLE START==== #fruit banana #color yellow #surface smooth... (0 Replies)
Discussion started by: borgeh
0 Replies

10. Shell Programming and Scripting

insert file 1 at a specific place of file 2

Hello, I need to search in file2 for class A : public B { and insert right after that the content of file1. I am a bit lost as to which tools (which bash functions, awk...). I should use. Thanks for some directions here. Regards (1 Reply)
Discussion started by: JCR
1 Replies
Login or Register to Ask a Question