String operation in csh AIX 4.3.2.0

Hi to everybody
i stuck on a simple thing i had a string and i want cut it , i try already few thing with the cut command but does not the way it should.
The script is in csh and running on AIX 4.3.2.0

here are few samples how the string can look like

FT71;1;1;1;;;1;31.01.2017 11:12:24;0
FT71;1;1;1;2;;1;31.01.2017 11:12:24;0
FT71;1;1;1;2;2;1;31.01.2017 11:12:24;0

The string should be cut always after the 7. delimiter even if there are no number between two delimiters like in sample 1 and 2 . That maybe the reason it doesnot works with the cut command.

Thanks a lot in advance

This is actually exactly the way cut works:

# printf "\"%s\"\n" $(echo "1;2;3;;;6;7;8" | cut -d';' -f1)
"1"
# printf "\"%s\"\n" $(echo "1;2;3;;;6;7;8" | cut -d';' -f4)
""

You probably didn't interpret the returned empty string as a result, like i did above in the little proof of concept.

Anyway, i strongly suggest you stop using csh and start using a less bugridden shell. AIX 4.3.2 (you might want to consider updating this to 4.3.3 ML12 too) offers a ksh88 and a ksh93.

I hope this helps.

bakunin

1 Like

You are working with the same data as in your other thread, looks like.

Another way to do it is

$ echo "FT71;1;1;1;;;1;31.01.2017 11:12:24;0" | awk '{ NF=6 } 1' FS=";" OFS=";" -

FT71;1;1;1;;

$

This has no benefits over cut if that's all you're doing... but if you're doing 93 more transformations on the data before you're done with it, they could all be rolled up in one awk call instead of 93 more shell externals.

1 Like

Hi Corona688,

thanks a lot for your help and Support,

Yes you are right the same string was in the other thread and your solution works perfect .
the cut on the string has to done every Iteration the change of the bit only has to done depending on some condition.

But the solution for the cut does not works on my side

 awk '{ NF=6 } 1' FS=";" OFS=";" $PATH_FILE > $TEMP_FILE

both file are the same , any ides what could be wrong

thanks in advanced

The routine is always the same: please post some sample of your input and a terminal session with some command executed on this data and its oucome: error messages, return codes, diagnostics and whatever is there.

Something like this:

I can't seem to make the ls -command work:

root@system # ls -l /bla/foo/file
/bla/foo/file not found
root@system # echo $?
2

Such a transcript i can analyse and would tell you that you probably mistyped the filename or some part of its path name. Telling me just " ls -l didn't work" i wouldn't be able to tell you anything.

I hope this helps.

bakunin

1 Like

Show field 8 and higher

cut -d";" -f8- file
1 Like

Thanks for your help

I guest i found the reason why the cut and awk doesn't work on my Project.
The file has only one line with without an CR.
If i just add an CR to this line both cut and awk works as from you recommented.
My Problem now the other process which create this text file will not add an CR to the this line

I'll Play around , hopefully i will found a solution for it

Kind regards

It is actually a <newline> instead of a <carriage-return> that UNIX and UNIX-like systems expect to find as line terminators.

To just add a <newline> character to the end of a file before using cut :

echo >> file; cut -d";" -f8- file

To add a <newline> character to the end of the input cut sees without modifying the file:

{ cat file; echo; } | cut -d";" -f8-

PS: Oops, the last command above only works with shells that use Bourne shell syntax; not csh .

The csh can do

( cat file; echo ) | cut -d";" -f8-

But this will produce an extra empty line if the input file is complete.
--
BTW the cut command in AIX 5.1 can handle an incomplete line.
Another method that might work in AIX 4.x:

read line < file
echo "$line" | cut -d";" -f8-

Faster but less flexible is

IFS=";" read x1 x2 x3 x4 x5 x6 x7 rest < file
echo "$rest"

hmm, now you got me interested in what exactly is the content of this file.

You got already various (and valuable) suggestions from my colleagues. My suggestion is, however, to spare us the guessworks and do the following: execute the shown command on the file and its output:

# cat /path/to/your/file | od -ax
<...output of the command here...>

The reason for this is that maybe some other "non-standard" traits of the file might include invisible characters and similar things that might confuse used commands. The output will make them visible (if they exist at all).

I hope this helps.

bakunin