Skip to content
Smarter by Design.Simpler for Business

Pipe Commands ​

Pipe Commands are the commands that carry the output a command prints on the screen to the next command with the | sign in the WEB-CLI. The output is filtered, counted, sorted and formatted line by line, or is written to a temporary file with to-file. The pipe is used not only after the sys-cmd tools but also after the API commands such as lb service list and after the built-in commands such as help and history.

14 commands
grep · wc · sort · to-file…
Line filtering, counting, sorting, field cutting, JSON processing and writing to a file.
At most 8 pipes
On a single line
At most eight | are used on a command line.
Runs on the device
Independent of the context
Whatever the selected v-device and route table are, the filtering is done on the device itself.
to-file
Temporary file
The output of the chain is written to a downloadable file.

Short syntax:

<command> | <pipe-command> [parameters] [ | <pipe-command> [parameters] … ]

Command Summary ​

TR7 WEB-CLI · pipe
# type | after the command and press Tab: the pipe commands
admin@TR7LBWAF01> sys-cmd ss -tan |
column    cut       grep      head      jq        nl        paste
sort      tac       tail      to-file   tr        uniq      wc
 
# the same list comes after the API commands too
admin@TR7LBWAF01> lb service list |
column    cut       grep      head      jq        nl        paste
sort      tac       tail      to-file   tr        uniq      wc
admin@TR7LBWAF01>  
CommandWhat it doesWriting
grepPasses the lines matching the patternTakes a single pattern; does not take parameters
wcCounts lines, words and charactersFree parameter
sortSorts the linesFree parameter
headShows the first linesFree parameter
tailShows the last linesFree parameter
uniqReduces the consecutively repeated lines to oneFree parameter
cutCuts a field or a character from the linesFree parameter
trTranslates or deletes charactersFree parameter
pasteMerges the lines side by sideFree parameter
jqProcesses and filters the JSON outputFree parameter; a filter starting with . is rejected
columnLays the output out in aligned columnsFree parameter
nlAdds numbers to the linesFree parameter
tacReverses the line orderFree parameter
to-fileWrites the output to a temporary fileThe file name is mandatory; --append, --stdout; at the end of the chain

In the pipe commands with a free parameter, what is written after the command name is carried to the tool as it is; Tab only shows the place of the next parameter in the form <wc-parameter-1>.

How It Works ​

SubjectBehavior
After which commandsAfter every command that prints output: the sys-cmd tools, the API commands (lb service list, settings dns show…) and the built-in commands such as help and history.
OrderThe chain works from left to right; the output of every command is the input of the next one. Only the output of the last command appears on the screen.
Where it worksThe pipe commands always work on the device itself. Even though the sys-cmd tool on the left works from within the selected v-device and route table, the filtering and the writing to a file are done on the device.
LimitAt most 8 pipes are used on a line; more than that gives the error Maximum pipe exceeded: 9>8 (Pipe limiti aşıldı: 9>8 in the Turkish interface).
Early endingWhen the command on the right closes, the commands on the left are stopped. For example, sys-cmd ping 10.20.0.15 | head -n 3 ends the ping as well after three lines.
StoppingCtrl+C stops the chain.
Error outputThe error messages of the pipe commands are written in red. The own error output of the sys-cmd tool on the left is not carried to the pipe and does not come to the screen.
Interactive commandsThe pipe cannot be used after telnet, frr-console and extend-data-disk: "Pipe" operator is not allowed after interactive commands.
RecordThe lines starting with sys-cmd are written to the user logs together with their pipe parts as System command executed.

Writing Rules and Limits ​

RuleDescriptionExample
No | inside quotesThe line is split at the | signs before the quotes; a | inside quotes is also counted as a pipe.—
Parameter with a spaceIt is taken inside single or double quotes.tr -s ' ' · grep "GET /health"
File path banIn the pipe commands other than grep and to-file, a parameter that contains / or .. or that starts with ~ or . is rejected: File path arguments are not allowed in pipe commands. The pipe commands are for processing the output coming from the left.jq '(.status)'
to-file at the very endto-file must be the last command of the chain; otherwise it gives the error to-file must be the last pipe process.… | grep 443 | to-file connections.txt
No shell operators>, >>, ;, && cannot be used (Invalid command); to-file is used to write to a file.| to-file output.txt --append

grep ​

Passes only the lines matching the pattern from the output coming from the left. On live streams (tcpdump, ping) the lines are filtered as they arrive.

OrderFieldStatusValue
1PatternRequiredThe text or the regular expression to be searched; it is written directly, without the field name being written. If it contains a space, it is taken inside quotes. Tab shows its place as <grep-pattern>
SubjectBehavior
A single patterngrep takes only one pattern, it does not accept parameters such as -i, -v and -c. The line grep -i estab gives the error Command not found: estab.
A pattern starting with -It is rejected: FIX: invalid grep pattern. If a pattern is not written, FIX: no grep pattern.
Upper / lower caseA distinction is made. To catch both writings, a character set is used: grep '[Ee]stab'.
Regular expressionThe pattern is interpreted as a regular expression; . matches every character. grep 10.20 passes both the line that contains 10.20 and the line that contains 10120.
ColorThe matching part is marked in color. The color codes also pass to the next pipe commands and to the file written with to-file.
TR7 WEB-CLI · grep
admin@TR7LBWAF01> sys-cmd ss -tan | grep ESTAB
admin@TR7LBWAF01> sys-cmd tcpdump -nn -i any port 53 | grep example.com
admin@TR7LBWAF01> lb service list | grep <vservice-name>
admin@TR7LBWAF01> help | grep file
admin@TR7LBWAF01>  

to-file ​

Writes the output of the chain to the temporary file area of the device. The files are seen with sys-cmd file list, are downloaded from the Link column and are deleted with sys-cmd file delete.

OrderFieldStatusValue
1File nameRequiredIt contains only letters, digits, -, _ and .; it cannot contain .. or a directory, otherwise Invalid filename. It is written directly, without the field name being written. Tab shows its place as <file-name>
FieldWhat it doesWhat is written after it
--appendIf a file with the same name exists, it appends to its end instead of overwriting itNo value is written
--stdoutWhile writing to the file, it also shows the output on the screenNo value is written
SubjectBehavior
DefaultThe output is written only to the file, nothing comes to the screen. If a file with the same name exists, it is overwritten.
With tcpdumpOn the sys-cmd tcpdump … | to-file <name>.pcap line, the packets are written in the pcap format that can be opened in Wireshark. In this case --stdout is not used; binary data is not read on the screen. Detail: tcpdump.
If the area fills upThe size and the fullness of the temporary area are seen with sys-cmd file disk show; space is freed with file delete or the area is enlarged with file disk change-size.
TR7 WEB-CLI · to-file
# only to the file
admin@TR7LBWAF01> sys-cmd dig app.example.com A +short | to-file dig-app.txt
# both show on the screen and save
admin@TR7LBWAF01> sys-cmd ss -tan state established | to-file connections.txt --stdout
# append to the end on every run
admin@TR7LBWAF01> sys-cmd ss -tan state established | grep 10.20.0.30 | to-file backend-connections.txt --append
# save the output of the API command
admin@TR7LBWAF01> settings dns show | to-file dns-settings.txt
admin@TR7LBWAF01>  

jq ​

Processes the output of a command that produces JSON: it selects fields, counts and formats.

SubjectBehavior
A filter starting with .It is caught by the file path ban and is rejected: the line jq '.status' gives the error File path arguments are not allowed in pipe commands. The filter is written by being taken inside parentheses: jq '(.status)'.
A filter containing / or ..It cannot be written because of the same rule.
Parameters-r writes the text without quotes, -c compresses every result into a single line.
TR7 WEB-CLI · jq
admin@TR7LBWAF01> sys-cmd curl -s http://10.20.0.30/api/status | jq '(.status)'
admin@TR7LBWAF01> sys-cmd curl -s http://10.20.0.30/api/status | jq -r '(.version)'
admin@TR7LBWAF01>  

Filtering and Formatting Commands ​

CommandFrequently used parametersExample
wc-l line · -w word · -c byte count… | wc -l
sort-n numeric · -r reverse · -k <n> according to the nth field · -t <separator> field separator · -u without repetition… | sort -rn
head-n <number> the number of first lines… | head -n 20
tail-n <number> the number of last lines… | tail -n 5
uniq-c writes the repeat count at the beginning · -d only the ones that repeat · -u only the ones that occur once. It merges only the consecutive repetitions; for this reason sort is used first… | sort | uniq -c
cut-d <separator> field separator · -f <n> field number · -c <range> character range… | cut -d ':' -f 1
tr-s <set> reduces the repeated character to one · -d <set> deletes · <set1> <set2> translates… | tr -s ' '
paste-s merges all the lines into a single line · -d <separator> merging separator · - - lays the lines out side by side two by two… | paste - -
column-t aligns the fields separated by a space like a table · -s <separator> field separator… | column -t
nlWithout a parameter it adds numbers to the lines; -b a numbers the empty lines too… | nl
tacIt does not take a parameter; the last line comes to the beginning… | tac

The table summarizes the frequently used parameters; the full list and the behavior depend on the version of the tool on the device.

Example Chains ​

TR7 WEB-CLI · A) The number of connections open to a backend
admin@TR7LBWAF01> sys-cmd ss -tn state established dst 10.20.0.30 | wc -l
admin@TR7LBWAF01>  
TR7 WEB-CLI · B) The 10 client addresses that open the most connections
admin@TR7LBWAF01> sys-cmd ss -tn state established | tr -s ' ' | cut -d ' ' -f 4 | cut -d ':' -f 1 | sort | uniq -c | sort -rn | head -n 10
admin@TR7LBWAF01>  
TR7 WEB-CLI · C) Only the summary of a long ping
admin@TR7LBWAF01> sys-cmd ping -c 50 10.20.0.15 | tail -n 2
admin@TR7LBWAF01>  
TR7 WEB-CLI · D) The first 20 lines of a live stream
# when 20 lines arrive, tcpdump is stopped as well
admin@TR7LBWAF01> sys-cmd tcpdump -nn -i any port 53 | head -n 20
admin@TR7LBWAF01>  
TR7 WEB-CLI · E) Searching and numbering in the API output
admin@TR7LBWAF01> lb service list | grep <vservice-name>
admin@TR7LBWAF01> history | tail -n 10 | nl
admin@TR7LBWAF01>  
TR7 WEB-CLI · F) Accumulating the filtered output
admin@TR7LBWAF01> sys-cmd ss -tn state established | grep 10.20.0.30 | to-file backend-connections.txt --append
admin@TR7LBWAF01> sys-cmd file list
admin@TR7LBWAF01>  

Things to Know ​

  • The pipe commands are for processing the output coming from the left. Parameters containing a file path are rejected; the content of a file in the temporary file area is seen with sys-cmd file content.
  • The heading also enters the line count. On the commands that give output in the table format, wc -l counts the heading lines too.
  • Colored output. The color codes of grep and of the commands that produce colored output are also written to the file; when the file is opened in a text editor, these codes can appear.
  • Tool versions. The parameters of the pipe commands with a free parameter depend on the version of the tool on the device.
  • For the system commands and the context, the System Commands page, and for the output formats of the API commands, the API Commands page can be looked at.