Ho un comando unix che effettua le seguenti operazioni:
head -c 2048 > test.txt
fondamentalmente sta prendendo il primo 2kb del file test.txt.
Possiamo fare qualcosa di simile nel prompt di windows cmd?
Ho un comando unix che effettua le seguenti operazioni:
head -c 2048 > test.txt
fondamentalmente sta prendendo il primo 2kb del file test.txt.
Possiamo fare qualcosa di simile nel prompt di windows cmd?
Risposte:
Semplificare questa risposta a causa del commento di @chubbsondubs.
-TotalCount conteggia le linee se legge nel testo, quindi forza sempre a leggere il file come byte, quindi il -TotalCount si riferirà solo ai byte e puoi ottenere un conteggio account.
Get-Content test.txt -Encoding byte -TotalCount 2KB | Set-Content test1.txt -Encoding byte
Maggiori informazioni qui: https://stackoverflow.com/questions/888063/powershell-to-get-the-first-x-mb-of-a-file
Da quello che posso dire che non puoi stampare per dimensione in modo nativo; C'è la type comando che genererà un intero file di testo, ma non è possibile specificare quanto si vuole produrre.
C'è anche il more comando, che ti permetterà di stampare le righe di un file. Queste sono alcune delle bandiere di more /?:
/E Enable extended features
/C Clear screen before displaying page
/P Expand FormFeed characters
/S Squeeze multiple blank lines into a single line
/Tn Expand tabs to n spaces (default 8)
Switches can be present in the MORE environment
variable.
+n Start displaying the first file at line n
files List of files to be displayed. Files in the list
are separated by blanks.
If extended features are enabled, the following commands
are accepted at the -- More -- prompt:
P n Display next n lines
S n Skip next n lines
F Display next file
Q Quit
= Show line number
? Show help line
<space> Display next page
<ret> Display next line
Se nessuno dei due funziona per te, puoi in alternativa installare Cygwin e puoi usare cat o head.