2023年8月3日星期四

linux cat create a txt file by EOF

EOF is a token that tells the cat command to terminate when it sees such a token in the subsequent lines.

cat > readme.txt << EOF

This is an input stream literal EOF


Followed by CTRL+D to terminate the command:

cat > readme.txt This is a readme file. This is a new line.

 

Append to an existing file, we can use the “>>” operator:

cat >> readme.txt
This is an appended line.

2023年8月1日星期二

powershell set-alias grep select-string

Destination: using grep in powershell like docker ps | grep "container-name"  

1. Powershell set-alias:
    Set-Alias -name grep -value Select-String

2. Try: docker ps -a | grep kind


PS C:\test> help select-string

名前
    Select-String

概要
    Finds text in strings and files.


構文
    Select-String [-Pattern] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII | BigEndianUnicode | Default | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] -InputObject <System.Management.Autom
    ation.PSObject> [-List] [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

    Select-String [-Pattern] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII | BigEndianUnicode | Default | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] [-List] -LiteralPath <System.String[]
    > [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]

    Select-String [-Pattern] <System.String[]> [-Path] <System.String[]> [-AllMatches] [-CaseSensitive] [-Context <System.Int32[]>] [-Encoding {ASCII | BigEndianUnicode | Default | OEM | Unicode | UTF7 | UTF8 | UTF32}] [-Exclude <System.String[]>] [-Include <System.String[]>] [-List] [-NotMatch] [-Quiet] [-SimpleMatch] [<CommonParameters>]


説明
    The `Select-String` cmdlet uses regular expression matching to search for text patterns in input strings and files. You can use `Select-String
    ` similar to `grep` in UNIX or `findstr.exe` in Windows.

    `Select-String` is based on lines of text. By default, `Select-String` finds the first match in each line and, for each match, it displays the
     file name, line number, and all text in the line containing the match. You can direct `Select-String` to find multiple matches per line, disp
    lay text before and after the match, or display a Boolean value (True or False) that indicates whether a match is found.

    `Select-String` can display all the text matches or stop after the first match in each input file. `Select-String` can be used to display all
    text that doesn't match the specified pattern.

    You can also specify that `Select-String` should expect a particular character encoding, such as when you're searching files of Unicode text.
    `Select-String` uses the byte-order-mark (BOM) to detect the encoding format of the file. If the file has no BOM, it assumes the encoding is U
    TF8.


関連するリンク
    Online Version: https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1&WT.mc_id=ps-gethel
    p
    about_Automatic_Variables
    about_Comparison_Operators
    about_Functions
    about_Quoting_Rules
    about_Regular_Expressions
    Get-Alias
    Get-ChildItem
    Get-Command
-- More  --