Sponsored Content
Top Forums Shell Programming and Scripting Splitting text string with "|" pipe delimiters Post 302426804 by Scrutinizer on Thursday 3rd of June 2010 02:52:53 AM
Old 06-03-2010
From a file you can use:
Code:
while IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8; do
  echo "Field O1 is $O1" 
  echo "Field O2 is $O2"
done<listing.txt

From a string you can use:
Code:
string="CUSTNAME|hostname|userid|gecos field|staff|disabled||SUDO"
IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8 <<EOF
$string
EOF

or in bash/ksh93:
Code:
IFS='|' read O1 O2 O3 O4 O5 O6 O7 O8 <<<"$string"



---------- Post updated at 08:52 ---------- Previous update was at 08:45 ----------

In ksh93/bash you can also use arrays, like so:
Code:
 IFS='|' O=( $string )

Code:
$ echo ${O[4]}
staff
$ echo ${O[0]}
CUSTNAME

 

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
Mail::Field::Date(3)					User Contributed Perl Documentation				      Mail::Field::Date(3)

NAME
Mail::Field::Date - a date header field INHERITANCE
Mail::Field::Date is a Mail::Field SYNOPSIS
use HTTP::Date 'time2iso'; my $field = Mail::Field->new(Date => time2iso()); DESCRIPTION
Represents one "Date" header field. METHODS
Constructors Mail::Field::Date->combine(FIELDS) See "Constructors" in Mail::Field Mail::Field::Date->extract(TAG, HEAD [, INDEX ]) See "Constructors" in Mail::Field Mail::Field::Date->new(TAG [, STRING | OPTIONS]) See "Constructors" in Mail::Field "Fake" constructors $obj->create(OPTIONS) See ""Fake" constructors" in Mail::Field $obj->parse() See ""Fake" constructors" in Mail::Field Accessors $obj->set(OPTIONS) -Option --Default Time undef TimeStr undef Time => SECONDS TimeStr => STRING A string acceptable to Date::Parse. $obj->stringify() See "Accessors" in Mail::Field $obj->tag() Mail::Field::Date->tag() See "Accessors" in Mail::Field Smart accessors $obj->text([STRING]) See "Smart accessors" in Mail::Field $obj->time([TIME]) Query (or change) the TIME (as stored in the field) in seconds. DIAGNOSTICS
Error: Undefined subroutine <method> called Mail::Field objects use autoloading to compile new functionality. Apparently, the mehod called is not implemented for the specific class of the field object. SEE ALSO
This module is part of the MailTools distribution, http://perl.overmeer.net/mailtools/. AUTHORS
The MailTools bundle was developed by Graham Barr. Later, Mark Overmeer took over maintenance without commitment to further development. Mail::Cap by Gisle Aas <aas@oslonett.no>. Mail::Field::AddrList by Peter Orbaek <poe@cit.dk>. Mail::Mailer and Mail::Send by Tim Bunce <Tim.Bunce@ig.co.uk>. For other contributors see ChangeLog. LICENSE
Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2007 Mark Overmeer <perl@overmeer.net>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html perl v5.16.3 2012-12-21 Mail::Field::Date(3)
All times are GMT -4. The time now is 10:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy