LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the syntax to use octal number in xargs for delimiter argument? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-syntax-to-use-octal-number-in-xargs-for-delimiter-argument-4175605692/)

tprabhu1983 05-11-2017 04:22 AM

What is the syntax to use octal number in xargs for delimiter argument?
 
man xargs:
--delimiter=delim, -d
The specified delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command.

The reason is:
Actual Input:
[root@rhel5 ~]# xargs -d\n
No
no
nn

Actual Output:
No
o

Expected Output:
No
no
nn

!!! 05-11-2017 06:55 AM

Try -d\\n or -d\\12 or -d\\xa See man printf. I think the shell "eats" the first backslash. Experiment using echo.

hydrurga 05-11-2017 06:57 AM

It's treating the \n as a literal 'n'.

Try:

Code:

xargs -d '\n'

tprabhu1983 05-11-2017 09:00 PM

Quote:

Originally Posted by !!! (Post 5709038)
Try -d\\n or -d\\12 or -d\\xa See man printf. I think the shell "eats" the first backslash. Experiment using echo.

Thanks for your reply.
With your suggestion, character "n" being saved, but it loses "escape character behaviour" of printing on the next line.

[root@rhel5 ~]# xargs -d\\xa
n1
n2
n3
n4

n1 n2 n3 n4
[root@rhel5 ~]# xargs -d\\12
n1
n2
n3

n1 n2 n3
[root@rhel5 ~]# xargs -d\\n
n1
n2
n3

n1 n2 n3
[root@rhel5 ~]# xargs -d\n
n1
n2
n3

1
2
3

tprabhu1983 05-11-2017 09:01 PM

Quote:

Originally Posted by hydrurga (Post 5709040)
It's treating the \n as a literal 'n'.

Try:

Code:

xargs -d '\n'

Thanks mate. With the below command, it has lost the "escape character behavior"

[root@rhel5 ~]# xargs -d '\n'
n1
n2
n3
n1 n2 n3
[root@rhel5 ~]# echo 1 \
> 2
1 2
[root@rhel5 ~]# echo 1\
> 2\
> 3\
> 4 |xargs -d\n
1234

scasey 05-12-2017 11:25 AM

Quote:

Originally Posted by tprabhu1983 (Post 5709410)
Thanks for your reply.
With your suggestion, character "n" being saved, but it loses "escape character behaviour" of printing on the next line.

[root@rhel5 ~]# xargs -d\\xa
n1
n2
n3
n4

n1 n2 n3 n4
[root@rhel5 ~]# xargs -d\\12
n1
n2
n3

n1 n2 n3
[root@rhel5 ~]# xargs -d\\n
n1
n2
n3

n1 n2 n3
[root@rhel5 ~]# xargs -d\n
n1
n2
n3

1
2
3

Typically the defined delimiter is not printed, so yes, it is "lost."

!!! 05-13-2017 10:49 AM

Add -n1
Or try -l
See man xargs. The -d seems to be for processing the input; -n for output.
Let us know, and use ThreadTools at top when resolved.

p.s. I meant: echo \n; echo \\n; echo '\n'; n="\n" echo $n

tprabhu1983 05-14-2017 09:19 AM

Quote:

Originally Posted by !!! (Post 5710104)
Add -n1
Or try -l
See man xargs. The -d seems to be for processing the input; -n for output.
Let us know, and use ThreadTools at top when resolved.

p.s. I meant: echo \n; echo \\n; echo '\n'; n="\n" echo $n

Perfect answer, thanks mate.

[root@rhel5 ~]# echo 1n 2n 3n |xargs -n1
1n
2n
3n

[root@rhel5 ~]# echo 1n 2n 3n |xargs -l
1n 2n 3n


All times are GMT -5. The time now is 01:48 AM.