awk script to remove spaces - examples don't show up correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script to remove spaces - examples don't show up correctly
# 15  
Old 12-22-2008
The above perl Snippet worked. Joeyg, your code worked but then bombed out on line 96 of 58000. I'm trying to see why. Thanks everyone for your help. I was surely stumped and skinning the cat the wrong way.
# 16  
Old 12-22-2008
Hammer & Screwdriver I would like to see line #96

Perhaps do a
head -100 myfile | tail -10 >tempfile

then post those 10 lines of the tempfile
# 17  
Old 12-22-2008
output as requested

I think the <B1> caused the failure.

Code:
3 910-0145                              BAT. CARRIER,TOP,SMK,FRONT LOAD BAT.     A             1.00000 EA  U J M  M  No
3 910-0146                              BAT.CARRIER,BTM,SMK,FRONT LOAD BAT.      C   3872      1.00000 EA  U J M  M  No
3 910-0147                              BAT. LOCKOUT,SMK,FRONT LOAD BAT.         A             1.00000 EA  U J M  M  No
3 1276-7102                             LABEL,BATTERY WARNING,1276               A             1.00000 EA  L I O  M  No
2 800-0472                               ASY,SUB,PCBA,SMK,DC,NGS,UL               C   5000      1.00000 EA  U J M  M  No
3 810-1962                              PCB,SMK,AC/DC,W/HUSH                     6   3561      1.00000 EA  U J M  M  No
3 810-2053                              CAP,CD,.01uf,<B1>20%50V,RADIAL              A             2.00000 EA  U J M  M  No
3 810-2788                              SOUNDER,PIEZO,EXTERNAL DRIVE,3.5KHz      A   5039      1.00000 EA  U J M  M  No
3 950-0087                              SCHEMATIC,0976(CA) DC,SMOKE ALARM        1   4230      1.00000 EA  L I O  M  No
3 1245-6503                             SWITCH,SN PLATED                         A             2.00000 EA  U J M  M  No

# 18  
Old 12-22-2008
Hammer & Screwdriver Either that <B1> or something else for 3 characters

the first example does show an issue with the data, while my second command corrects for that oddity.

Code:
> awk -v space=$space '{print substr($0,1,37)substr(space,1,substr($0,1,1))substr($0,41)}' file126 | tr "~" " "
3 910-0145                              BAT. CARRIER,TOP,SMK,FRONT LOAD BAT.     A             1.00000 EA  U J M  M  No
3 910-0146                              BAT.CARRIER,BTM,SMK,FRONT LOAD BAT.      C   3872      1.00000 EA  U J M  M  No
3 910-0147                              BAT. LOCKOUT,SMK,FRONT LOAD BAT.         A             1.00000 EA  U J M  M  No
3 1276-7102                             LABEL,BATTERY WARNING,1276               A             1.00000 EA  L I O  M  No
2 800-0472                              ASY,SUB,PCBA,SMK,DC,NGS,UL               C   5000      1.00000 EA  U J M  M  No
3 810-1962                              PCB,SMK,AC/DC,W/HUSH                     6   3561      1.00000 EA  U J M  M  No
3 810-2053                              CAP,CD,.01uf,<B1>20%50V,RADIAL              A             2.00000 EA  U J M  M  No
3 810-2788                              SOUNDER,PIEZO,EXTERNAL DRIVE,3.5KHz      A   5039      1.00000 EA  U J M  M  No
3 950-0087                              SCHEMATIC,0976(CA) DC,SMOKE ALARM        1   4230      1.00000 EA  L I O  M  No
3 1245-6503                             SWITCH,SN PLATED                         A             2.00000 EA  U J M  M  No
> awk -v space=$space '{print substr($0,1,37)substr(space,1,substr($0,1,1))substr($0,41)}' file126 | tr "~" " " | sed 's/<B1>/ /'
3 910-0145                              BAT. CARRIER,TOP,SMK,FRONT LOAD BAT.     A             1.00000 EA  U J M  M  No
3 910-0146                              BAT.CARRIER,BTM,SMK,FRONT LOAD BAT.      C   3872      1.00000 EA  U J M  M  No
3 910-0147                              BAT. LOCKOUT,SMK,FRONT LOAD BAT.         A             1.00000 EA  U J M  M  No
3 1276-7102                             LABEL,BATTERY WARNING,1276               A             1.00000 EA  L I O  M  No
2 800-0472                              ASY,SUB,PCBA,SMK,DC,NGS,UL               C   5000      1.00000 EA  U J M  M  No
3 810-1962                              PCB,SMK,AC/DC,W/HUSH                     6   3561      1.00000 EA  U J M  M  No
3 810-2053                              CAP,CD,.01uf, 20%50V,RADIAL              A             2.00000 EA  U J M  M  No
3 810-2788                              SOUNDER,PIEZO,EXTERNAL DRIVE,3.5KHz      A   5039      1.00000 EA  U J M  M  No
3 950-0087                              SCHEMATIC,0976(CA) DC,SMOKE ALARM        1   4230      1.00000 EA  L I O  M  No
3 1245-6503                             SWITCH,SN PLATED                         A             2.00000 EA  U J M  M  No
>

# 19  
Old 12-23-2008
Just wanted to say thanks to joeyg and chris for the help with this problem. I made adjustments to joeyg's code and it formatted everything perfectly. I did come across with some special characters (40 instances) but removed them and added them back after I was completed with the 60,0000 lines. Thanks for everything guys. I couldn't have done it without any of your suggestions.


chris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to remove spaces and mv a file

I've tried various solutions to move a file name with spaces and nothing seems to work. I need to take a date as input, prepend it to a filename with spaces then remove the spaces and mv the file to the new name. #!/bin/ksh # if (( $# != 1 )) then echo "Usage: `basename $0` <DATE> " ... (5 Replies)
Discussion started by: w_s_s
5 Replies

2. Shell Programming and Scripting

Why does this awk script not work correctly?

I have a large database with English on the left hand side and Indic words on the left hand. It so happens that since the Indic words have been entered by hand, there are duplicates in the entries. The structure is as under: English headword=Indic gloss,Indic gloss A small sample will... (6 Replies)
Discussion started by: gimley
6 Replies

3. AIX

Showmount don't show NFS4

Configure nfs4 on aix ok i did all chnfsdom #return correct domain chnfs -r /export chnfs -p /export configured and shared pseudo root #etc/exports /export -nfsroot /var/pubblica -exname=/export/pubblica,vers=4,sec=sys:krb5p:krb5i:krb5:dh,rw exportfs -a mount correct mount... (1 Reply)
Discussion started by: Linusolaradm1
1 Replies

4. Shell Programming and Scripting

Remove spaces / tabs from variable in script

I want to remove extra spaces from variable in aix script. We retrieve the data from oracle database and then print the values. We have a value on 90th position. When we execute the query on sqlplus it shows the length of 90th position as 3, but when we use the same query in aix script it shows... (5 Replies)
Discussion started by: lodhi1978
5 Replies

5. Shell Programming and Scripting

AWK: Remove spaces before processing each line?

Hi, all I have a file containing the following data: name: PRODUCT_1 date: 2010-01-07 really_long_name: PRODUCT_ABCDEFG I want to get the date (it is "2010-01-07" here), I could use the following code to do that: awk... (6 Replies)
Discussion started by: kevintse
6 Replies

6. Shell Programming and Scripting

How to remove spaces using awk,sed,perl?

Input: 3456 565 656 878 235 8 4 8787 3 7 35 878 Expected output: 3456 565 656 878 235 8 4 8787 3 7 35 878 How can i do this with awk,sed and perl? (10 Replies)
Discussion started by: cola
10 Replies

7. Shell Programming and Scripting

how to remove blank spaces of a file with awk??

hello how to remove blank spaces of a file with awk?? i´m trying awk '{gsub(" ","",$0); print $0;}' filename.txt but it answers syntax error near line first of all i did this for download from netbackup database jobs privilege bpdbjobs -report -M sv88 -gdm -header |cut -c-1024... (4 Replies)
Discussion started by: pabloli150
4 Replies

8. Shell Programming and Scripting

Don't show keyboard input on terminal

I am developing a script that will run with '/bin/ksh' shell. The script is intended to receive a password by keyboard input, but for security reasons I would like to hide what the user is typing. The keyboard input is being caught by 'read' command. exmaple : echo "Please type your new... (1 Reply)
Discussion started by: marianor31
1 Replies

9. Shell Programming and Scripting

Variable with $ do not show correctly

Hey guys i need help i have a script to push a password to a remote server the only problem is the $ENCRYPT variable has $'s in it (from the encrypted password in the shadow file) and they drop out when apending to the shadow file via the usermod command so $1$Q/6a08n$EoAcBuR/YnoCQC shows up as... (3 Replies)
Discussion started by: insania
3 Replies

10. Linux

Why don't my clock show am or pm?

Is it not possible to get the "Digital" clock in KDE 3.3 to show am or pm? Well I just noticed the plain clock setting is the only one that shows it. (2 Replies)
Discussion started by: CTroxtell21
2 Replies
Login or Register to Ask a Question