Problem in extracting data using cut/awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in extracting data using cut/awk command
# 1  
Old 06-07-2017
Problem in extracting data using cut/awk command

Hi Everyone,

I have a very simple problem and i am stuck in that from last 8 days. I tried many attempts, googled my query but all in vain.

I have a text file named "test.txt"
In that suppose i have contents like:

Code:
Java:
1 Object oriented programming language
2 Concepts of Abstraction and Interfaces
3 Inheritance comes into role.
4 Constructor used to initialize object.

C:
1 Procedural language
2 No inheritance
3 No constructor
4 Different scope variables are present here.

Now suppose i want to cut the whole Content of java and store it in a variable in a script and same for C and store it in another variable. Which command is suitable as i want to have output in the same format as input.


I tried cut command with output delimiter and awk command but Didnt achieve my goal. Any help highly appreciated ! Smilie
# 2  
Old 06-07-2017
This is very close to your other request. Couldn't you apply / adapt the solutions given there?
# 3  
Old 06-07-2017
Hi RudiC,

The solution that you gave didn't work there.So i tried to make a simple text file and try only this problem.
# 4  
Old 06-07-2017
The solutions given there were tested on the samples provided there and DID work. Mayhap they didn't for you and / or a different setup. You'll need to adapt them, then.

My proposal to this "new" problem would be very close to the ones over there, so you'd need to reconsider adapting it.

But, as this request is nearly identical to the other one, Don Cragun's question still applies (and please make sure to answer it!):

Is the subject of this thread a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework Questions forum under special homework rules.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.
# 5  
Old 06-07-2017
O i ll once again try with what you suggested. But i dont think it ll work as i tried it many times Smilie

---------- Post updated at 12:25 AM ---------- Previous update was at 12:21 AM ----------

RudiC, the awk command that you mentioned gives result:

Code:
1:Object oriented programming language 2: Concepts of Abstraction and Interfaces 3 Inheritance comes into role...... and so on

All in one line only Smilie
# 6  
Old 06-07-2017
Please answer the homework question!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting text using cut command

Hi All, I need to extract text 'ULTIMATE and 4spaces after it' from below line 77"2686"2010-11-21 14:09:13.000"4"I"200"1"2010-11-21 14:09:14.000"001:S087110131 ULTIMATE 4.99 T"" I have used cut command : a=`echo $line | cut -f9 -d '"' | cut -c20-31` echo $a But... (5 Replies)
Discussion started by: angie1234
5 Replies

2. UNIX for Dummies Questions & Answers

Data manipulation with cut command

Hi, I need some help with the cut command, can i use it to cut a certain number of characters from string starting from the end. say my string is like this some junk data xyz1@pqr.com xyz2@pqr.com some more junk data I can't exactly say how many email addresses are present in between. But the... (4 Replies)
Discussion started by: poojabhat
4 Replies

3. Shell Programming and Scripting

awk - extracting data from a series of files

Hi, I am trying to extract data from multiple output files. I am able to extract the data from a single output file by using the following awk commands: awk '/ test-file*/{print;m=0}' out1.log > out1a.txt awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4 ;m=0}' out1.log >... (12 Replies)
Discussion started by: p_sun
12 Replies

4. Shell Programming and Scripting

Problem in getting data from a loop using grep and cut

The script is following : for each_rec in <file_name> do count=`cut -c -2 ${each_rec} | grep "45"` echo ${count} if ] then amount=`cut -c 24-35 ${each_rec}` echo ${amount} else echo "failed" fi done And the file looks like below : ... (4 Replies)
Discussion started by: mady135
4 Replies

5. Shell Programming and Scripting

Using Awk for extracting data in specific format

please help me writing a awk script 001_r.pdb 0.0265185 001_r.pdb 0.0437049 001_r.pdb 0.0240642 001_r.pdb 0.0310264 001_r.pdb 0.0200482 001_r.pdb 0.0146746 001_r.pdb 0.0351344 001_r.pdb 0.0347856 001_r.pdb 0.036119 001_r.pdb 1.49 002_r.pdb 0.0281011 002_r.pdb 0.0319908 002_r.pdb... (5 Replies)
Discussion started by: phoenix_nebula
5 Replies

6. Shell Programming and Scripting

Extracting last parsed segment with the cut command

I can see in the man pages how cut can be used to extract a specified string by using the -f qualifier. However, I can't find anywhere how to specify the "last" parsed segment with the cut command. If the string you are parsing is (or can be) differant each time the script is run, but you know... (4 Replies)
Discussion started by: phudgens
4 Replies

7. Shell Programming and Scripting

Need to read data from a file (cut/awk)

Hi list, i have an orcale spool file with SQL> select COMPMAP as SVC, ITEM, UNIT, sum(JAN), sum(FEB) SVC ITE U SUM(JAN) SUM(FEB) ------ --- - ---------- ---------- 401500 IOC Q 14 14 406200 LC Q 1 1 410124 IOC Q 5 4 410124 LC... (1 Reply)
Discussion started by: rejirajraghav
1 Replies

8. Programming

Help in extracting data with command from file in C

Hi, I have a file which stores the following array :- 1,2,3,4,5.........16,17,18,19,20 This file has few hundreds of inputs of these lines. I would like to read this file one line at a time; and assign to an array which is separated by ",". I tried to do fgets command however,... (10 Replies)
Discussion started by: ahjiefreak
10 Replies

9. Shell Programming and Scripting

Problem in extracting vector data

Hi, Currently I have two files; A and B. File A has below data:- -3 + <1 2 3 4 5 6 7 8 1 2 > - 1] -2 + <8 8 3 4 0 3 7 9 1 3 > - 1] -1 + <3 7 3 4 8 2 7 2 1 2 > - 1] -3 + <2 2 3 4 3 1 7 8 8 2 > - 1] and File B has below data:- <9 1 1 4 2 6 3 8 8 9 > From these two files, I... (2 Replies)
Discussion started by: ahjiefreak
2 Replies

10. UNIX for Advanced & Expert Users

For loop problem extracting data

I have a problem with my loops. I have a file called users.dat, it has all the users in it. Then I extracted a list of users sending out number of mails with date from Netscape logs. The extracted list (mailuse.dat) has 3 fields: username, number of mails, date. (One user can show up several... (2 Replies)
Discussion started by: nitin
2 Replies
Login or Register to Ask a Question