Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell - Read a text file with two words and extract data Post 302983625 by dandaryll on Friday 14th of October 2016 03:52:31 AM
Old 10-14-2016
Question Shell - Read a text file with two words and extract data

hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line.

Example that worked for me with text file having 3 fields only:
Code:
#!/bin/bash
IFS=", "
while read f1 f2 f3
do
	echo "$f1"
	echo "$f2"
	echo "$f3"
done < test2.txt > output.txt

and output.txt shows this

Code:
cheek
gingivae
hard
palate
inferior
lip
soft
palate
superior
lip
tongue
uvula

cat test2.txt shows this:
Code:
cheek, gingivae, hard,
palate, inferior, lip,
soft, palate, superior
lip, tongue, uvula

BUT NOW I have a list with more fields and have two words that I need:

new test2.txt shows this:
Code:
right, kidney, right ureter,
urethra, urinary, bladder,
left, adrenal gland, abdominal aorta, inferior vena cava, right renal vein, right renal artery, rectum, uterus

how can I list these 2 word terms into a list with each in its own individual line

THANKS!

Last edited by Scrutinizer; 10-14-2016 at 05:03 AM.. Reason: CODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to read all the unique words in a text file

How can i read all the unique words in a file, i used - cat comment_file.txt | /usr/xpg6/bin/tr -sc 'A-Za-z' '/012' and cat comment_file.txt | /usr/xpg6/bin/tr -sdc 'A-Za-z' '/012' but they didnt worked..... (5 Replies)
Discussion started by: aditya.ece1985
5 Replies

2. Shell Programming and Scripting

To read and separate number and words in file and store to two new file using shell

hi, I am a begginer in unix and i want to know how to open a file and read it and separate the numbers & words and storing it in separate files, Using shell scripting. Please help me out for this. Regards S.Kamakshi (2 Replies)
Discussion started by: kamakshi s
2 Replies

3. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

4. Shell Programming and Scripting

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

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

5. Shell Programming and Scripting

How to read the data from the text file in shell script?

I am having one text file and i need to read that data from my shell script. I will expain you the scenario: Script look like: For name type 1: For age type 2: For Salary type3: echo "Enter the input:" read the data if input is 1 then go to the Text file and print the... (2 Replies)
Discussion started by: dineshmurs
2 Replies

6. Shell Programming and Scripting

Script to read file and extract data by matching pattern

Hello, I have a file ( say file1) which has lines like below. xxxx:xxxx,yyyy,1234,efgh zzzz:zzzz,kkkk,pppp,1234,xxxx,uuuu,oooo dddd:dddd here the word before ":" ( ie: xxxx) is the file name and the string after : are also file names, but each file name separated by "," In case of... (20 Replies)
Discussion started by: pradeepmacha
20 Replies

7. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

8. Shell Programming and Scripting

I need to extract uique words from text file

Hello programmers, I need to create a list of unique words from a text file using PERL...may i have the code for that please? Thank you (1 Reply)
Discussion started by: alsohari
1 Replies

9. 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

10. 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
ldi_ident_from_dev(9F)					   Kernel Functions for Drivers 				    ldi_ident_from_dev(9F)

NAME
ldi_ident_from_dev, ldi_ident_from_stream, ldi_ident_from_dip, ldi_ident_release - ldi cookie management SYNOPSIS
#include <sys/sunldi.h> int ldi_ident_from_dip(dev_info_t *dip, ldi_ident_t *lip); int ldi_ident_from_dev(dev_t dev, ldi_ident_t *lip); void ldi_ident_from_stream(struct queue *sq, ldi_ident_t *lip); void ldi_ident_release(ldi_ident_t li); PARAMETERS
li ldi identifier. lip ldi identifier pointer. dip Pointer to device info node dev Device number sq Pointer to a stream queue DESCRIPTION
The ldi_ident_from_dev() function allocates and returns an ldi identifier that is associated with the device number specified by dev. The new ldi identifier is returned via the ldi identifier pointer parameter lip. The ldi_ident_from_dip() function allocates and returns an ldi identifier that is associated with the device info node pointed to by dip. The new ldi identifier is returned via the ldi identifier pointer parameter lip. The ldi_ident_from_stream() function allocates and returns an ldi identifier that is associated with the stream pointed to by queue. The new ldi identifier is returned via the ldi identifier pointer parameter lip. The ldi_ident_release() function releases an identifier that was allocated via one of the ldi_ident_from()* functions. RETURN VALUES
The ldi_ident_from_dev(), ldi_ident_from_dip(), and ldi_ident_from_stream() functions return 0 upon success. All of these functions return EINVAL for invalid input parameters. CONTEXT
These functions can be called from user or kernel context. SunOS 5.11 3 June 2003 ldi_ident_from_dev(9F)
All times are GMT -4. The time now is 08:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy