Converting another line to another format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting another line to another format
# 1  
Old 06-09-2015
Converting another line to another format

Hi there,

How can i shorten this:

Code:
grep -ri "Password must meet complexity requirements" "$line" | sed  's/\t/<\/td><td>/' | sed 's/^.*:/<tr><td>/'| sed  's/$/<\/td><\/tr>/'

I am looking for a shorter alternative of sed. What I was trying to do is to change the string output format from

Code:
LPO/ULT0151_Password Policy.txt-Password must meet complexity requirements   Enabled

to:
Code:
<tr><td>Password must meet complexity requirements</td><td>Enabled</td></tr>

Moderator's Comments:
Mod Comment Please use CODE tags for all sample input, sample output, AND code segments.

Last edited by Don Cragun; 06-10-2015 at 04:01 AM.. Reason: Add CODE tags again.
# 2  
Old 06-09-2015
Why not make it workable first?

Unless $line is a file, this wont work, remove "$line" and then try:
Code:
echo "$line" | grep ....

Regarding the sed question, sorry, looks good to me

hth
# 3  
Old 06-10-2015
The entire problem could be solved with e.g. awk. Unfortunately there's no samples (in code tags) that we could work on.

---------- Post updated at 07:52 ---------- Previous update was at 07:44 ----------

Applying wild assumptions to your first post, try
Code:
awk '
/Password must meet complexity requirements/    {sub (/^.*-/,"")
                                                 $0="<tr><td>" $0 "</tr></td>"
                                                 sub ("\t","</td><td>")
                                                 }
1
' file
<tr><td>Password must meet complexity requirements</td><td>Enabled</tr></td>

# 4  
Old 06-10-2015
Thread hijack removed to here.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in converting the file format

Hi All, I need help in converting the mentioned file format into desired output format using awk. Could anyone help me in this? Below is the input.. Date Account Campaign AdGroup Keyword Conversion Revenue Var1 Var2 Var3 Var4 Var5 10 20 30 ... (8 Replies)
Discussion started by: Ravi S M
8 Replies

2. UNIX for Dummies Questions & Answers

Converting dates to iso format

Hi , i am trying to read a tsv file record by record and change the date column with iso date format. it have different dates with format like mm/dd/yyyy HH:MM:SS EST ,i am trying serarch for the date format lke this yyyy-mm-dd HH:MM:SS EST and replace to it if dosent match that format . Any... (2 Replies)
Discussion started by: vikatakavi
2 Replies

3. Shell Programming and Scripting

Converting the date format

Hi All, I am new to this forum. Could anyone help me to resolve the following issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1 5022090,4,1,6648,88,,,,,4/1/2011... (6 Replies)
Discussion started by: av_sagar
6 Replies

4. Shell Programming and Scripting

converting Date format

Dear Friends, We have date in output as MM/DD/YYYY format and I want to convert it in DD/MM/YYYY format. e.g. 12/31/2010 to 31/12/2010 We have checked forum for the solution but we are not getting matching query. Please guide us Thanks Anushree. (6 Replies)
Discussion started by: anushree.a
6 Replies

5. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

6. Shell Programming and Scripting

Converting text to certain format

Hi Forum. I'm trying to convert the following text using "sed" or "awk" or "tr" but with no luck. From: EDW_WHOLESALE_VORTEX To: __ Any help is greatly appreciated. (9 Replies)
Discussion started by: pchang
9 Replies

7. Shell Programming and Scripting

Converting file format

My input file is Pipe delimited with 10 fields, I am trying to create a tab delimited output file with 6 fields from the provided input file. Below is sample data Input file abc||2|PIN|num||||www.123.com|abc@123.com| bcd||2|PIN|num|||||abc@123.com|... (3 Replies)
Discussion started by: pasupuleti81
3 Replies

8. Shell Programming and Scripting

converting date format

Hi Please anyone to help to write script to convert date to 'yyyy-mm-dd'(If column is date convert) because my file has large and lot of date colums. If file is small ,using awk command to achive. cat file1|awk 'BEGIN {FS=OFS='|'}... (7 Replies)
Discussion started by: mohan705
7 Replies

9. Shell Programming and Scripting

converting text to csv format

I am trying to check each line and based on first two digits, the comma needs to be place. I checked in the earlier post where the text is converted to csv with a tab delimited. Here is the test file that needs to be changed to csv 11 051701 22 051701 330123405170105170112345... (13 Replies)
Discussion started by: gthokala
13 Replies
Login or Register to Ask a Question