LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-05-2013, 02:49 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Rep: Reputation: 16
concatenate string with in a comma delimited file


have a few questions here.

I have a comma delimited file that contains several lines like:
Code:
Deploy_ACC_FBL.Legacy.ACV_Production,1,2012.09.32,SUCCESS,
Deploy_ALU_Production,1,2012.09.3,FAILURE,e012835
Deploy_CMI_AdjusterXML_Production,2013-03-13_16-50-14,MBC.ClientMidtierInterface_2013.02.58,FAILURE,e009137
Deploy_PRT_Production,2013-03-15_22-05-00,prt_2012.11.57,SUCCESS,e009137
Deploy_RRE_Production,2012-08-29_09-52-17,2012.08.134,SUCCESS,e012835
Deploy_RRE_Production,2012-09-02_07-35-57,RRE_2012.08.141,FAILURE,e009137
I need to take the first string in the file:
Deploy_ up to the first comma(,) then strip off the 'Deploy_' and the '_Production' then concatenate the result to the third string in the same line. I have found the method to accomplish the separation and selection:
Code:
 sysid=`awk -F"," '{print $1}' $inputfile | cut -d_ -f2- | rev | cut -d_ -f2- | rev `
  tagnfo=`awk -F"," '{print $3}' $inputfile`
but my problem is concatenating the result while in a loop reading the file a line at a time and output the result into a new file.

resulting line evaluated line:

Deploy_RRE_Production,2012-08-29_09-52-17,2012.08.134,SUCCESS,e012835

like:
Deploy_RRE_Production,2012-08-29_09-52-17,RRE_2012.08.134,SUCCESS,e012835

another hanging issue is detecting the existence of a value in the third string anything prior to the _2012.08.141; remove the value prior to the '_' and replace with the value from the first string 'sysid' as some are not correct or in proper case.

hope this makes sense. thank you.
 
Old 04-05-2013, 10:57 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,408

Rep: Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834
This is a bash solution that I think meets your requirements.
Code:
#!/bin/bash

IFS=","
file=$1

while read -a aline ; do
  temp=${aline[0]#Deploy_};
  temp=${temp%_Production};
  echo ${aline[0]},${aline[1]},$temp"_"${aline[2]##*_},${aline[3]},${aline[4]};
done < $file
Using your data I get this output.
Quote:
Deploy_ACC_FBL.Legacy.ACV_Production,1,ACC_FBL.Legacy.ACV_2012.09.32,SUCCESS,
Deploy_ALU_Production,1,ALU_2012.09.3,FAILURE,e012835
Deploy_CMI_AdjusterXML_Production,2013-03-13_16-50-14,CMI_AdjusterXML_2013.02.58,FAILURE,e009137
Deploy_PRT_Production,2013-03-15_22-05-00,PRT_2012.11.57,SUCCESS,e009137
Deploy_RRE_Production,2012-08-29_09-52-17,RRE_2012.08.134,SUCCESS,e012835
Deploy_RRE_Production,2012-09-02_07-35-57,RRE_2012.08.141,FAILURE,e009137
 
Old 04-08-2013, 08:08 AM   #3
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
well, thank you very much. That works great.

I had a few questions to understand the script but after performing some searches, I found the answers.

I greatly appreciate the assistance. I constantly am learning new methods and am amazed by what one can accomplish with linux. Plus, the online community support is much better than most believe nor care to understand the benefit.

Thank you!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Concatenate the output to comma delimited hattori.hanzo Programming 1 11-23-2010 07:13 AM
output pid's from ps to a comma delimited file machielr Linux - General 11 04-08-2010 03:33 AM
parse comma delimited text string sunilvadranapu Suse/Novell 4 06-16-2009 12:05 AM
column re-alignment - space delimited to comma delimited hattori.hanzo Linux - Newbie 9 03-05-2009 12:54 AM
comma delimited file cdragon Programming 5 06-21-2002 07:55 PM


All times are GMT -5. The time now is 12:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration