Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

UNIX SED – Convert Vertical List to Horizontal CSV

Posted on October 29, 2016 By David Kittell

If you’ve had to take a vertical list to horizontal list before you know how difficult it can be.

You may have a different setup than my example but the code provided below should help in most cases.

==================================================
Origin URL        | http://kittell.net
Action URL        | http://kittell.net/api
User Name Field   | username
Password Field    | password
User Name         | kittell1
Password          | SomethingSecret
Created Time      | 12/9/2015 2:20:52 PM
Password Strength | Very Strong
Password File     | C:\Users\dkittell\database
==================================================

==================================================
Origin URL        | http://kittell.net
Action URL        | http://kittell.net/api
User Name Field   | username
Password Field    | password
User Name         | kittell2
Password          | SomethingSecret
Created Time      | 12/9/2015 2:20:52 PM
Password Strength | Very Strong
Password File     | C:\Users\dkittell\database
==================================================

The code below is still a work in progress but does what I need it to for now, it’s very ugly but it works.

rm -f temp1
head -11 list.txt | sed '/==================================================/d' > temp
sed -i -e 's/,$/\n/' temp

while read line
do
echo $line | cut -f1 -d '|' | sed 's/[ \t]*$//'
#echo $sHeaders
done < temp > temp1

tr -s '\r\n' ',' < temp1 > listheaders.txt

tr -s '\r\n' ',' < list.txt | sed -e 's/,$/\n/' > temp | tr -s '==================================================' '\n' < temp > listd.txt

sed -i -e "s/Origin URL        | //g" listd.txt
sed -i -e "s/Action URL        | //g" listd.txt
sed -i -e "s/User Name Field   | //g" listd.txt
sed -i -e "s/Password Field    | //g" listd.txt
sed -i -e "s/User Name         | //g" listd.txt
sed -i -e "s/Password          | //g" listd.txt
sed -i -e "s/Created Time      | //g" listd.txt
sed -i -e "s/Password Strength | //g" listd.txt
sed -i -e "s/Password File     | //g" listd.txt

cat listheaders.txt listd.txt > listc.txt && rm -f listheaders.txt listd.txt temp temp-e temp1
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Oracle – Table Structure

Posted on November 14, 2013October 26, 2015

SELECT atc.TABLE_NAME ,atc.COLUMN_NAME ,atc.DATA_TYPE ,CASE DATA_TYPE WHEN ‘VARCHAR2’ THEN ‘(‘ || DATA_LENGTH || ‘)’ WHEN ‘NUMBER’ THEN CASE WHEN DATA_PRECISION IS NOT NULL THEN ‘(‘ || DATA_PRECISION || CASE WHEN DATA_SCALE <> 0 THEN ‘,’ || DATA_SCALE END END || CASE WHEN DATA_PRECISION IS NOT NULL THEN ‘)’ END END…

Read More

Ektron – Remove Content/Folder Permissions

Posted on August 20, 2014October 26, 2015

Use EXTREME caution on this query. I recommend you do a backup of your database before you run this script as this will remove all permissions that someone has setup on Ektron. TRUNCATE TABLE [permissions_tbl]; UPDATE [content] SET [inherit_permissions] = 0 ,[inherit_permissions_from] = 0 ,[private] = 0; Originally Posted on…

Read More

UNIX Bash – Create Date/Time File Name

Posted on August 25, 2016October 4, 2019

When you need to create a log file or some dated archive echo "This is a dated file $(date +%Y_%m_%d_%H.%M.%S)" > testfile_`date +%Y_%m_%d_%H.%M.%S`.txt The format can be modified slightly based on date formatting. Originally Posted on August 25, 2016Last Updated on October 4, 2019 All information on this site is…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes