How to cut data block from .txt file in shell scripting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to cut data block from .txt file in shell scripting
# 1  
Old 04-23-2009
Question How to cut data block from .txt file in shell scripting

Hi All,
Currently i have to write a script.
For which i need to cut a block from .txt file.
I know the specific word that starts the block and ends the block.
Can we do it in shell scripting..?
Please suggest....
# 2  
Old 04-23-2009
Use the search function, one of the results:

https://www.unix.com/shell-programmin...data-file.html
# 3  
Old 04-23-2009
But here i dont know the how many lines there can be after the specific word.
is there something like ... between 2 keyword whatever data found can be sent to the new file...?
# 4  
Old 04-23-2009
I used this also...

x=`grep -n "Cluster Resource Groups ===" test123.txt | cut -d ":" -f1`
y=`grep -n "Cluster Resource ===" test123.txt | cut -d ":" -f1`
a=`echo ${x} + 1 | bc`
b=`echo ${y} -1 | bc`
echo $x $y $a $b
sed -ne "${a},${b}p" test123.txt

But its giving me this error -->
syntax error on line 1, -1
sed: Function syntax error on line 1, ,-1p cannot be parsed.
# 5  
Old 04-23-2009
Take a look at a sed1liners
# 6  
Old 04-23-2009
The sed command is your answer and you can use text to start and stop the print function.
Code:
sed -n '/Cluster Resource Groups ===/,/Cluster Resource ===/p' test123.txt

# 7  
Old 04-25-2009
Thanx... it worked... Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. Programming

Writing a UNIX shell script to call a C function and redirecting data to a .txt file

Hi, I am complete new to C programming and shell scripting. I just wrote a simple C code to calculate integral using trapezoid rule. I am prompting user to pass me No. of equally spaced points , N , upper and lower limit. My code looks as follows so far: #include<stdio.h> #include<string.h>... (2 Replies)
Discussion started by: bjhjh
2 Replies

4. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

5. Shell Programming and Scripting

How to extract data from XML file using shell scripting?

Hi , I have input file as XML. following are input data #complex.xml Code: <?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: arun_kohan
1 Replies

6. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

7. Shell Programming and Scripting

Shell scripting- cut the location of the file

Hi, I need to just cut the location of file and give it as input to the other command. For example: ct lsview | grep kavya- * kavya-telecom-view /first/nso01/disk2/views/kavya-telecom-view.vws I need only the location like /first/nso01/disk2/views/kavya-telecom-view.vws.How to cut that... (4 Replies)
Discussion started by: kkalyan
4 Replies

8. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

9. Shell Programming and Scripting

Extracting data from file-shell scripting--please help

hello friends, my file is like 123 |asd|asd|asd 123_1|awd|asw|asw 121 |wer|qwe|wee 124 |weq|qwe|iop 1_23 |bla|blh|bha 145 |ghj|jkl|ghj 146 |qwe|qwe|wer 154 |asd|wer|qw_e 134_5|qwe|wer|qw_e is their any solution to retrive only those lines which are having only 3 numerical letters... (20 Replies)
Discussion started by: PankajChawla
20 Replies

10. Shell Programming and Scripting

Shell scripting to extract data from file

Hi, i want to fetch the data from the alert log file, for a particular time interval. Example : Alert log content : Thu Mar 18 08:47:36 2010 Completed: alter database open Thu Mar 18 19:13:38 2010 MMNL absent for 6390 secs; Foregrounds taking over Fri Mar 19 08:30:52 2010... (1 Reply)
Discussion started by: Pinki018
1 Replies
Login or Register to Ask a Question