Shell script UNIX to read text file line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script UNIX to read text file line by line
Prev   Next
# 1  
Old 11-05-2017
Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name

data_file.txt

Code:
column_name file_name
col1               file1
col2               file2
col3               file1
col4               file1
col5               file2

now, i would like to output below result to a text file, which returns all the column name by file name as below.

Code:
file_name   column_name
file1           col1,col3,col4
file2           col2,col5

how can i write a shell script to read the data_file.txt line by line and output the result as above by file name.

Last edited by rbatte1; 11-06-2017 at 09:58 AM.. Reason: Changed QUOTE tags to CODE tags
 
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 read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

2. Shell Programming and Scripting

How to read a file, line by line in UNIX script?

#!/bin/bash file1="yxd" for file in `cat file3.txt`; do cat $file1 | awk '{split($1,dp,"."); lend=length(dp); if(lend>2) { dom=dp"."dp; split($2,ipl,","); for(i=1; i<=length(ipl); i++) { if(ipl~/:/) { if(ipl~/:/) i++; rip=ipl; i++; raq=ipl; rtq=0; si=i+4; for(;i<si;i++) rtq+=ipl; rsub="";... (2 Replies)
Discussion started by: veeruasu
2 Replies

3. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

4. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

7. Shell Programming and Scripting

how can u read a file line by line in shell script ?

hello , plz help for below script req:- how can we read a file line by line in shell script ? (4 Replies)
Discussion started by: abhigrkist
4 Replies

8. UNIX for Dummies Questions & Answers

shell script to read file line by line

Hi, I need to read a text file from shell script line by line and copy the feilds of each line. Below is the complete requirement. I've text file which contains ... pgm1 file11 file12 file13 pgm2 file21 file22 pgm3 file31 file32 file33 I'll give input as... (4 Replies)
Discussion started by: ani12345
4 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

10. Shell Programming and Scripting

Script does not read the last line of text file

Hello, I have got a script that reads a text file, and have got three problems that I an struggling with. 1. The script does not read the last line in the text file 2. within the second 'elif' within the script I included a 'break' - the script runs successfully (except for the first... (2 Replies)
Discussion started by: jermaine4ever
2 Replies
Login or Register to Ask a Question
tabs(1) 						      General Commands Manual							   tabs(1)

NAME
tabs - Sets tab stops on terminals SYNOPSIS
tabs [-n] [-T terminal] [+m [margin]] tabs [predefined_tab_flag] [-T terminal] [+m [margin]] tabs [-T terminal] [+m [margin]] number [,number]... tabs [--tab_format_file] The tabs command clears up to 20 previous tabs and sets up to 40 tabs on the terminal according to the supplied tab specifications. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: tabs: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Specifies repetitive tab stops separated by a uniform number of column positions, n, where n is a single-digit number. The default usage of tabs with no arguments is equivalent to tabs -8. If you use -0, the tab stops are cleared and no new ones are set. Identifies the terminal so that tabs can set tabs and margins correctly. The terminal argument is one of the conventional terminal names supported by your system. [Tru64 UNIX] If the terminal you specify is not known to the system, tabs tries a general value that works for most terminals. If you do not provide a -T option, tabs uses the TERM shell variable. Moves all tabs to the right number columns, and makes column number+1 the left margin. If m is given without a value, 10 is assumed. The leftmost margin on most terminals is defined by m0. Specifies that tabs should be set to a structured language format that is known to the system. See the section Predefined Tab Flags for a description of these flags. [Tru64 UNIX] Causes tabs to read a file named tab_format_file for format information. The first line of the file must be in the format shown in the section Format Specifications to use this method. The file may contain other lines which are ignored by tabs. Note [Tru64 UNIX] The double dash (--) format is mandatory with this option. OPERANDS
Sets tabs at the named column numbers (a list in ascending order, separated by commas). You can specify up to 40 numbers. If any number except the first has a plus sign prefix, the prefixed number is added to the previous number for the next setting. Thus, the tab lists 1,10,20,30 and 1,10,+10,+10 provide the same tab settings. DESCRIPTION
If you use the tabs command with no options or operands, the terminal tabs are reset to the system defaults for your terminal type. If only the -T option is used, tabs are reset to the defaults for that terminal type. [Tru64 UNIX] When you use the tabs command, always consider the leftmost column number to be 1, even if your terminal refers to it as 0 (zero). Tab-stop position n means that tabbing to position n causes the next character output to be in the n+1th column position on that line. Predefined Tab Flags [Tru64 UNIX] The flags described in the following list provide formats required by most structured programming languages. Some of these flags require that a particular format line be present in the file being manipulated. This is indicated in the list. Sets the tabs to 1, 10, 16, 36, and 72. Sets the tabs to 1, 10, 16, 40, and 72. Sets the tabs to 1, 8, 12, 16, 20, and 55 (COBOL normal format) Sets the tabs to 1, 6, 10, 14, and 49 (COBOL compact format, columns 1 to 6 omitted). With this code, the first column position corresponds to card col- umn 7. One space gets you to column 8, and a tab reaches column 12. Files using this code must include the following format specifica- tion: <:t-c2 m6 s66 d:> [Tru64 UNIX] See Format Specifications later in this reference page. Sets the tabs to 1, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, and 67 (COBOL compact format with more tabs than -c2). This is the recommended format for COBOL. Files using this code must include the following format specification: <:t-c3 m6 s66 d:> Sets the tabs to 1, 7, 11, 15, 19, and 23 (FORTRAN). Sets the tabs to 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, and 61 (PL/I). Sets the tabs to 1, 10, and 55 (SNOBOL). Sets the tabs to 1, 12, 20, and 44. Format Specifications [Tru64 UNIX] A format specification consists of a sequence of arguments separated by blanks and enclosed in brackets and colons: <: :>. Each argument consists of a keyletter and an optional value which immediately follows it. The following arguments can be used: [Tru64 UNIX] Specifies tab settings. The value for tabs can be: [Tru64 UNIX] A list of column numbers separated by commas, indicating tab stops at the specified columns. [Tru64 UNIX] A - (dash) followed by a number n, specifying tabs stops every n columns. [Tru64 UNIX] A preset tab specification, for example -a2. [Tru64 UNIX] Specifies a maximum line size, or length. The size specification must be an integer. (The value of size is checked after tabs have been expanded but before the margin is prepended.) [Tru64 UNIX] Specifies a number of spa- ces to be inserted at the beginning of each line. The margin specification must be an integer. [Tru64 UNIX] Indicates that the line con- taining the format specification is to be deleted from the converted file. [Tru64 UNIX] If a format specification can be disguised as a comment, for example * <:t5,10,15 s75 m5:> *, you do not need to include the d keyletter. [Tru64 UNIX] Indicates that the current format should prevail only until another format specification is encountered in the file. [Tru64 UNIX] Default values of t-8 and m0 are assumed if t and m arguments are not included in the specification; if s is not included, line size is not checked. If the first line of a file does not contain a format specification, these defaults are assumed for the entire file. NOTES
The tabs command assumes that standard output is the terminal. If standard output is redirected, the results are unpredicable. Full oper- ation of all capabilities may be restricted by the hardware. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To set tabs every four spaces, enter: tabs -4 To clear all tabs, enter: tabs ENVIRONMENT VARIABLES
The following environment variables affect the execution of tabs: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Determines the terminal type if the -T option is not used. SEE ALSO
Commands: expand(1), nroff(1), stty(1), tset(1) Standards: standards(5) tabs(1)