LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2020, 07:31 PM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
Having two delimiter instead of only one


How to have two delimiter instead of only one of char. / as in this

Code:
while read -d':' -d'/' l;do echo $l ;done < file.txt
not work, how to solve it ?
 
Old 12-30-2020, 03:17 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Code:
IFS=:/ read -ra words <<<'aa:bb/cc'
for w in ${words[@]}
do echo $w
done
BTW, your code above doesn't need word delimiters at all: the variable l gets assigned the whole line anyway.

Last edited by shruggy; 12-30-2020 at 03:46 AM.
 
2 members found this post helpful.
Old 12-30-2020, 04:01 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
My try:
Code:
echo 'Long:string/multiple/parts' |
tr ':/' '\n\n' | while read -r W; do echo "#$W#"; done
#Long#
#string#
#multiple#
#parts#
 
1 members found this post helpful.
Old 12-30-2020, 09:06 AM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
An awk solution ...

With this InFile ...
Code:
Long:string/multiple/parts
... this awk ...
Code:
awk '{}'1 RS=[/:] $InFile >$OutFile
... produced this OutFile ...
Code:
Long
string
multiple
parts
Daniel B. Martin

.
 
1 members found this post helpful.
Old 12-30-2020, 09:12 AM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
A tr solution ...

With this InFile ...
Code:
Long:string/multiple/parts
... this tr ...
Code:
tr '[/:]' '\n' <$InFile >$OutFile
... produced this OutFile ...
Code:
Long
string
multiple
parts
Daniel B. Martin

.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How use CUT -d 'delimiter' is delimiter is a TAB? frenchn00b Programming 12 11-06-2013 03:17 AM
Can mkisofs create two small ISO images instead of one big one? thomas.hedden Linux - Software 4 02-18-2013 11:42 AM
[SOLVED] how to remove delimiter and append as one string greenpool Linux - Newbie 5 09-10-2011 08:26 PM
Two heads, to keyboards, two mice, two users on one machine? PsychosisNode Linux - General 5 07-23-2006 07:42 PM
two, two, two cd players in one blistfix Linux - Newbie 3 07-03-2001 04:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration