Copy selective lines from text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy selective lines from text file
# 8  
Old 05-11-2011
Re : Working , but some more doubts

@ ahamed101 :

The code is now working, thank you very much. But I have some other doubts whch I would like to clarify with you.!

1.
I am running this on Fedora 14, when I gave this command it said :
Code:
bash: cacm dataset/cacm.all: Permission denied

This file is located on a removable NTFS Partition of my hard drive. Then I tried to change the permissions of the file by giving the following command
Code:
chmod 644 cacm\ dataset/cacm.all

But the permissions of the file do not change,even if I try as super user the permissions stay the same. then I coped the file to home directory and with the old permissions, it worked. is there any way to get around this? Or do we need to copy the file to the Linux Partitions and then only work on it??

2.
Some of the content in the .T tag , dot not end at a line, for eg. there is this one:-
Code:
.T
The Problem of Programming Communication with
Changing Machines A Proposed Solution-Part 2
.B

So is it possible to copy multiple lines.. that is from the starting of .T tag to the starting of the next tag .B??

3.
The script you have given me has a lot of AWK scripting. I am not a very good at shell scripts. I thought of doing the job first with C , but then realized that shell script would be faster. Tried with Grep first, but realized that Grep is not very powerful and will not take me very far. I know very litttle AWK . Could you please tell me from where I can learn more??
# 9  
Old 05-11-2011
1. Not sure

2.
Code:
awk '/^\.I/{_2="file"$2".txt"}/^\.T/{print $0>>_2;while(getline != /.B/){print $0>>_2}}/^\.N/{x=$0;getline;print x"\n"$0>>_2}' infile

3. Check this

regards,
Ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Shell Programming and Scripting

Copy lines from x to y to another file

OS : RHEL 7.2 Shell : bash I have a file which has lines like below I want to copy from 2nd line to the 6th line and copy(redirect) those lines to another file. $ cat patterns.txt hello world hello asia hello europe hello africa hello america hello antartica hello... (9 Replies)
Discussion started by: omega3
9 Replies

3. Shell Programming and Scripting

Bash selective copy folders and content to another location

I'm looking for a bash scrypt to copy some folders and some of the content to another location. I'm a teacher and very noobish with programming language anyway what I'm looking for , I have this director structure Main director "Students" with subfolders "john";"daisy";"work" etc .. and some of... (2 Replies)
Discussion started by: brickleul
2 Replies

4. Shell Programming and Scripting

How to copy selective list of files to a directory?

Hi I have 3 directories indexes_with_ts indexes_without_ts process_indexes in each directories it contains *.sql how do I accomplish this: for all the files found in indexes_without_ts, copy the corresponding file in indexes_with_ts to process_indexes. i.e. for... (2 Replies)
Discussion started by: jediwannabe
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Perl: selective printing of lines

Hi, I have a file with lines like this. 2 7 18 ggcgt anna 2 7 18 hhchc sam 3 7 18 hhdjcc ross 4 7 18 hhcjd jenny 0 8 21 jjdhs sam 3 8 21 kkok bush 2 9 24 kosss BrenhamIf the values of the second column are equal, print only those lines with the least first column value. So in... (5 Replies)
Discussion started by: polsum
5 Replies

7. Shell Programming and Scripting

selective replacing text using sed/perl

Hi, I have the following text which I want to search and replace using perl and sed. I would appreciate any help. Please notice the file contains schema name with a single dot and a double dot . &&WEBDIR_SCHEMA. and &&WEBDIR_SCHEMA .. } I would like to change it to the acutal schema... (5 Replies)
Discussion started by: jville
5 Replies

8. Shell Programming and Scripting

sed/awk script selective insert between lines

Hi I have a file in the foll. format *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD AV* Data *FIELD RF* *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD RF* (4 Replies)
Discussion started by: dunstonrocks
4 Replies

9. Shell Programming and Scripting

selective printing of lines

Hi all , i need to grep for a string in a text file and print the string and the 3rd line above it. As always , Thanks. (4 Replies)
Discussion started by: okiedokie
4 Replies

10. Shell Programming and Scripting

clip selective text and minus

After doing some scripting in a log file, I am left with some lines like this. 10:00:00 Received Message Message ID 1 10:05:00 Published Message Message ID 1 10:10:00 Received Message Message ID 2 10:15:00 Published Message Message ID 2 10:20:00 Received Message Message ID 3 10:26:00... (1 Reply)
Discussion started by: srini123
1 Replies
Login or Register to Ask a Question