How to make spaces in between?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make spaces in between?
# 1  
Old 09-28-2016
How to make spaces in between?

Hi Guru's,

i have a problem and hope you could help me on how to go about it. I have a file which is impossible to decipher. Please see below.

Code:
INPUT
121014259981568JBAUT30JaniceBautistaMANGER TECHNICIANActiveTech
121014259879380DMASH03DavidMashawLEAD TECHNICIANActiveClerk

I wanted to have an output as shown below.

Code:
OUTPUT
JBAUT30 Janice Bautista MANGER TECHNICIAN
DMASH03 David Mashaw LEAD TECHNICIAN

Thanks.

Last edited by rbatte1; 09-28-2016 at 11:31 AM.. Reason: Removed bold in code block.
# 2  
Old 09-28-2016
Hello Ernesto,

Could you please try following and let me know if this helps you. But Input_file should be same as shown sample Input_file(ditto exact) else it would provide different output too.
Code:
awk '{sub(/[0-9]+/,X,$0);match($0,/[[:alpha:]]+[[:digit:]]+/);ID=substr($0,RSTART,RLENGTH);DES=substr($0,RLENGTH+1);match(DES,/[a-zA-Z]+/);NAME=substr(DES,RSTART,RLENGTH);gsub(/.* |Active.*/,X,DES);sub(/[a-z]+/,"& ",NAME);VAL=ID FS NAME FS DES;gsub(/LEAD|MANGER/," &",VAL);print VAL}' Input_file

EDIT: Adding a non-one liner form of above solution too now.
Code:
awk '{
        sub(/[0-9]+/,X,$0);
        match($0,/[[:alpha:]]+[[:digit:]]+/);
        ID=substr($0,RSTART,RLENGTH);
        DES=substr($0,RLENGTH+1);
        match(DES,/[a-zA-Z]+/);
        NAME=substr(DES,RSTART,RLENGTH);
        gsub(/.* |Active.*/,X,DES);
        sub(/[a-z]+/,"& ",NAME);
        VAL=ID FS NAME FS DES;
        gsub(/LEAD|MANGER/," &",VAL);
        print VAL
     }
    '   Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-28-2016 at 11:29 AM.. Reason: Adding a non-one liner form of above solution successfully too now.
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-28-2016
Quote:
Originally Posted by ernesto
Hi Guru's,

i have a problem and hope you could help me on how to go about it. I have a file which is impossible to decipher. Please see below.

Code:
INPUT
121014259981568JBAUT30JaniceBautistaMANGER TECHNICIANActiveTech
121014259879380DMASH03DavidMashawLEAD TECHNICIANActiveClerk

I wanted to have an output as shown below.

Code:
OUTPUT
JBAUT30 Janice Bautista MANGER TECHNICIAN
DMASH03 David Mashaw LEAD TECHNICIAN

Thanks.
Hopefully this sed one liner might work...
Code:
sed -e 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/\([a-z]\)\([A-Z]\)/\1 \2/g;s/\([A-Z]\)\([A-Z]\)\([a-z]\)/\1 \2\3/g;s/^\([0-9]*\) //'  file

This User Gave Thanks to shamrock For This Post:
# 4  
Old 09-28-2016
Hi,

Another version. ( output/sed is purely based on given input in post#1, it might not work if input lines are different)

Code:
$ cat file
121014259981568JBAUT30JaniceBautistaMANGER TECHNICIANActiveTech
121014259879380DMASH03DavidMashawLEAD TECHNICIANActiveClerk

Code:
sed -re 's/^[0-9]+([A-Z]{5}[0-9]{2})([A-Z^A-Z][a-z]*)([A-Z][^A-Z][a-z]*)([a-z]*)([A-Z][^a-z]*)([A-Z][A-Za-z]*)/\1 \2 \3\4 \5/'  file

Gives output:
Code:
JBAUT30 Janice Bautista MANGER TECHNICIAN
DMASH03 David Mashaw LEAD TECHNICIAN

This User Gave Thanks to greet_sed For This Post:
# 5  
Old 09-28-2016
Quote:
Originally Posted by shamrock
Hopefully this sed one liner might work...
Code:
sed -e 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/\([a-z]\)\([A-Z]\)/\1 \2/g;s/\([A-Z]\)\([A-Z]\)\([a-z]\)/\1 \2\3/g;s/^\([0-9]*\) //'  file

Hello Shamrock,

Thank you for nice code, would like to add here IMHO. Above code gives extra string at last from ActiveTechorActiveClerk, so to remove them too just a little modification of you code as follows should do the trick.
Code:
 sed -e 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/\([a-z]\)\([A-Z]\)/\1 \2/g;s/\([A-Z]\)\([A-Z]\)\([a-z]\)/\1 \2\3/g;s/^\([0-9]*\) //;s/ Active.*//g'  Input_file

Thanks,
R. Singh
These 2 Users Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add extra spaces to make all lines the same length?

Hello to all, I'm trying to format a file to have all lines with the same length (the length of the longest line) adding needed extra spaces at the end. Currently I have the awk script below that adds one space the end of each that have a lenght lower than 35, but I don't know how to add... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

2. Shell Programming and Scripting

Append spaces the rows to make it into a required fixed length file

I want to make a script to read row by row and find its length. If the length is less than my required length then i hav to append spaces to that paritucular row. Each row contains special characters, spaces, etc. For example my file contains , 12345 abcdef 234 abcde 89012 abcdefgh ... (10 Replies)
Discussion started by: Amrutha24
10 Replies

3. Programming

Issue with make, no rule to make target etc.

I have been trying to split up my src directory to clear out files that are not re-compiled very often. Now I have the following setup in my trunk, trunk/bld trunk/src/ trunk/src/src_server trunk/makefile.linux In the make file, I have compile rules SOURCELOC = src # compile src c++... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

4. UNIX for Dummies Questions & Answers

Difference between configure/make/make install.

Hi, While installation of apache on linux, we perform the below tasks. 1) Untar 2) configure 3) make 4) make install. I wanted to understand the difference and working of configure/make/make install. Can any one help me understanding this? Thanks in advance. (1 Reply)
Discussion started by: praveen_b744
1 Replies

5. Solaris

Gani Network Driver Won't Install - make: Fatal error: Don't know how to make targ...

I attached a README file that I will refer to. I successfully completed everything in the README file until step 4. # pwd /gani/gani-2.4.4 # ls COPYING Makefile.macros gem.c Makefile Makefile.sparc_gcc gem.h Makefile.amd64_gcc ... (1 Reply)
Discussion started by: Bradj47
1 Replies

6. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

7. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

8. Linux

Error in issuing a make and make install

Hi, Recently I install a package and try to do a make and make install. However, in the make it gives me below error:- make:Nothing to be done for 'install-exec-am' make:Nothing to be done for 'install-data-am' Can anyone please explain to me what does this mean? I have been trying... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

9. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

10. UNIX for Dummies Questions & Answers

make and make install commands

Hi there, I am installing a package at the moment on to my Solaris version 8 and I have run into a problem with the 'make' command. I have installed the package using the 'pkgadd' command and I am now at the stage where I have to use the 'make' command followed by the 'make install'... (4 Replies)
Discussion started by: gerwhelan
4 Replies
Login or Register to Ask a Question