Sponsored Content
Top Forums Shell Programming and Scripting Splitting text string with "|" pipe delimiters Post 302426798 by frans on Thursday 3rd of June 2010 01:50:31 AM
Old 06-03-2010
can be done so
Code:
FIELDS=( F1 F2 F3 F4 F5 F6 F7 F8 )
IFS='|'
while read ${FIELDS[@]}
do
    for F in ${FIELDS[@]}
    do
        echo "$F is ${!F}"
    done
done < listing.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

2. Shell Programming and Scripting

get string out of text file after "= "

I have a text file like: The name of the project = "Symbion centrifuge" The name of the subsytem = "motor demon" now i would like to read the string after the = into a variable to write it to another file. later use like: sed s/'PROJECTNAME'/"$projectname"/ <header.tex >temp ... (9 Replies)
Discussion started by: vivelafete
9 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

sort text having delimiter with "|" (pipe)

i am having text file below NARGU S S 12358 SALES REP |22| Acccount/s RAJU R B 64253 SALES REP |12| Acccount/s RUKMAN S 32588 SALES REP |10| Acccount/s NARGUND S S 12356... (3 Replies)
Discussion started by: suryanarayana
3 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

8. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

9. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

10. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies
READ(P) 						     POSIX Programmer's Manual							   READ(P)

NAME
read - read a line from standard input SYNOPSIS
read [-r] var... DESCRIPTION
The read utility shall read a single line from standard input. By default, unless the -r option is specified, backslash ( '' ) shall act as an escape character, as described in Escape Character (Back- slash) . If standard input is a terminal device and the invoking shell is interactive, read shall prompt for a continuation line when: * The shell reads an input line ending with a backslash, unless the -r option is specified. * A here-document is not terminated after a <newline> is entered. The line shall be split into fields as in the shell (see Field Splitting ); the first field shall be assigned to the first variable var, the second field to the second variable var, and so on. If there are fewer var operands specified than there are fields, the leftover fields and their intervening separators shall be assigned to the last var. If there are fewer fields than vars, the remaining vars shall be set to empty strings. The setting of variables specified by the var operands shall affect the current shell execution environment; see Shell Execution Environ- ment . If it is called in a subshell or separate utility execution environment, such as one of the following: (read foo) nohup read ... find . -exec read ... ; it shall not affect the shell variables in the caller's environment. OPTIONS
The read utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines. The following option is supported: -r Do not treat a backslash character in any special way. Consider each backslash to be part of the input line. OPERANDS
The following operand shall be supported: var The name of an existing or nonexisting shell variable. STDIN
The standard input shall be a text file. INPUT FILES
None. ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of read: IFS Determine the internal field separators used to delimit fields; see Shell Variables . LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine 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). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES . PS2 Provide the prompt string that an interactive shell shall write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a here-document is not terminated after a <newline> is entered. ASYNCHRONOUS EVENTS
Default. STDOUT
Not used. STDERR
The standard error shall be used for diagnostic messages and prompts for continued input. OUTPUT FILES
None. EXTENDED DESCRIPTION
None. EXIT STATUS
The following exit values shall be returned: 0 Successful completion. >0 End-of-file was detected or an error occurred. CONSEQUENCES OF ERRORS
Default. The following sections are informative. APPLICATION USAGE
The -r option is included to enable read to subsume the purpose of the line utility, which is not included in IEEE Std 1003.1-2001. The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified. EXAMPLES
The following command: while read -r xx yy do printf "%s %s " "$yy" "$xx" done < input_file prints a file with the first field of each line moved to the end of the line. RATIONALE
The read utility historically has been a shell built-in. It was separated off into its own utility to take advantage of the richer descrip- tion of functionality introduced by this volume of IEEE Std 1003.1-2001. Since read affects the current shell execution environment, it is generally provided as a shell regular built-in. If it is called in a sub- shell or separate utility execution environment, such as one of the following: (read foo) nohup read ... find . -exec read ... ; it does not affect the shell variables in the environment of the caller. FUTURE DIRECTIONS
None. SEE ALSO
Shell Command Language COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 READ(P)
All times are GMT -4. The time now is 09:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy