logo
down
shadow

Use fgetcsv for tab delimited file


Use fgetcsv for tab delimited file

By : Hyper
Date : November 22 2020, 07:01 PM
With these it helps Is it possible to use fgetcsv in PHP to open a tab-delimited file?
code :


Share : facebook icon twitter icon
(sed/awk) How to convert a field-delimited (like a csv) file into a txt with fixed-sized tab-delimited columns?

(sed/awk) How to convert a field-delimited (like a csv) file into a txt with fixed-sized tab-delimited columns?


By : user2596207
Date : March 29 2020, 07:55 AM
will help you I have something like a csv file in which the field delimiter is "@".
code :
awk -F@ '{for(i=1;i<=NF;i++){printf "%-20s", $i};printf "\n"}' input.csv
$ cat input.csv
1254343123@John@Smith@24@Engineer@Washington
23@Alexander@Kristofferson-Brown@35@Economic Advisor@Kent
$ awk -F@ '{for(i=1;i<=NF;i++){printf "%-20s", $i};printf "\n"}' input.csv
1254343123          John                Smith               24                  Engineer            Washington
23                  Alexander           Kristofferson-Brown 35                  Economic Advisor    Kent
#!/bin/bash

fldwth=20

awk -v fw=$fldwth -F@ '{for(i=1;i<=NF;i++){printf "%-*s", fw,$i};printf "\n"}' input.csv
How to convert a pipe delimited file into a tab delimited file and show results in listbox VBA

How to convert a pipe delimited file into a tab delimited file and show results in listbox VBA


By : Vincent Pau
Date : March 29 2020, 07:55 AM
I wish this help you Okay so after spending some time researching it and a lot of time debugging i finally figured it out so i figured i'd post my results in case somebody else ever needs help with this
code :
    Function PipeToTab(ByVal OriginalText As String) As String
'Runs though current line of text stored in original text'
 On Error GoTo error1
 Dim ThisString As String, NewString As String, a As Integer
 NewString = ""

For a = 1 To Len(OriginalText)
'checks to see if current char is white space and if it is removes it
    If Mid(OriginalText, a, 1) = " " Then
    'checks to see if current char is | and if it is changes it to char$(9) (tab)
    ElseIf Mid(OriginalText, a, 1) = "|" Then
        NewString = NewString & Chr$(9)
    Else
        NewString = NewString & Mid(OriginalText, a, 1)
    End If
Next
    PipeToTab = NewString
 Exit Function
error1:
MsgBox (Err.Description)

 End Function`
    `Private Sub Convert_File_Click()
    On Error GoTo error1
    Dim pipe_file As Variant
    Dim ThisString As String
    Dim a As Integer
    Dim rfs, rts, InputFile, wfs, wts, OutputFile As Object
    Dim InputFileName, OutputFileName, OriginalText, updatedText As String

    ' File initialization
    'open the original source file and create the output file with the name desired from textbox.
    InputFileName = Me.FilePath 'filepath is a textbox that holds the location 
    'and name of where you want the textfile to go 
        Set rfs = CreateObject("Scripting.FileSystemObject")
        Set InputFile = rfs.GetFile(InputFileName)


    'open the text streams
        Set rts = InputFile.OpenAsTextStream(1, -2) 'Read
        Set wts = OutputFile.OpenAsTextStream(8, -2) 'Append

    'then put line into conversion function and get the updated text
    'move onto the next line until EOF

        While rts.AtEndofStream = False
             OriginalText = rts.ReadLine 'read current line of file
             If OriginalText <> Empty Then
               updatedText = PipeToTab(OriginalText)
               wts.WriteLine updatedText 'put updated text into newly created file(output file)
            Else
            End If
        Wend`
'Output file clean up
    wts.Close
'Input File clean up
    rts.Close


End If
'clear out filestreams
    Set OutputFile = Nothing
    Set wfs = Nothing
    Set wts = Nothing
    Set InputFile = Nothing
    Set rfs = Nothing
    Set rts = Nothing

Exit Sub
error1:
' File Clean up
rts.Close
Set InputFile = Nothing
Set rfs = Nothing
Set rts = Nothing

'Output
wts.Close
Set OutputFile = Nothing
Set wfs = Nothing
Set wts = Nothing
MsgBox (Err.Description)
End Sub
PHP fgetcsv() Tab Delimited Isn't working correctly

PHP fgetcsv() Tab Delimited Isn't working correctly


By : user3024604
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a tab delimited txt file (ex. "US California LA") that needs to be output word for word. Could anyone help me figure out how to get it to break word for word?? , Delimiter is third parameter of fgetcsv. Try:
code :
while(($row = fgetcsv($file, 1000, "\t")) !== false)
{
    print($row[0]);
}
Batch: convert pipe delimited text file to comma delimited csv file

Batch: convert pipe delimited text file to comma delimited csv file


By : Jian Hun
Date : March 29 2020, 07:55 AM
around this issue If you want to read the file stored in variable INPUT, you need to read it as %INPUT% to do that (you stated INPUT literally, with odd quotation). When you specify '' within the set of for /F, the part within () is interpreted as a command rather than a file, so for /F tries to execute command input which cannot be found and so the script fails. I stringly recommend to put "" around the specified file, together with the usebackq option, in order to avoid trouble with white-spaces in paths/file names.
If you want to write into the file stored in variable OUTPUT, you must not redirect the echo to somewhere else (you placed >>"%~2" in the code).
code :
@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem Define constants here:
set "INPUT=%~1"
set "OUTPUT=%~2"

if not defined INPUT exit /B 1
if not defined OUTPUT set "OUTPUT=con"
> "%OUTPUT%" (
    for /F usebackq^ delims^=^ eol^= %%L in ("%INPUT%") do (
        set "LINE=%%L"
        setlocal EnableDelayedExpansion
        echo(!LINE:^|^|=,!
        endlocal
    )
)

endlocal
exit /B
echo("!LINE:||=","!"
Customer Number,Customer Name,Partner Number,Partner Name,Customer Country
1ABC,Jame,1234,Anny,USA
2DEF,Susan,5678,Prissy,UK
"Customer Number","Customer Name","Partner Number","Partner Name","Customer Country"
"1ABC","Jame","1234","Anny","USA"
"2DEF","Susan","5678","Prissy","UK"
Empty CSV file produced when reading 1 row of tab delimited data and exporting to '+' delimited

Empty CSV file produced when reading 1 row of tab delimited data and exporting to '+' delimited


By : AMJ
Date : March 29 2020, 07:55 AM
Any of those help The following two processing steps are causing the behavior you observed:
code :
(Get-Content $stepfile1) | select -Skip 1 | Set-Content $stepfile2
Import-Csv $stepfile2 -Delimiter "`t" | Export-Csv $stepfile3 -Delimiter "+" -NoTypeInformation
Header   Row                  Header   Row
Record1  Data1                Record1  Data1
                              Record2  Data2
Record1  Data1                Record1  Data1
                              Record2  Data2
Record1  Data1                Record1  Data1
                              Record2  Data2
                              Record1+Data1
                              Record2+Data2
{
  "Record1": "Record2",
  "Data1": "Data2"
}
$filename = Join-Path $dir "${file}${ext}"

$records = (Get-Content $filename).Replace('+', '').Replace("`t", '+') |
           Select-Object -Skip 1

$newsequencenumber = [int](Get-Content $sequencefile) + 1
$pstgfile = Join-Path $dir "PSTG_NCDLPSTG.${newsequencenumber}"

"HEADER=$(Get-Date -Format d)+PSTG" | Set-Content $ptsgfile
$records | Add-Content $ptsgfile
"TRAILER = $($records.Count)" | Add-Content $ptsgfile
Related Posts Related Posts :
  • Which is the best php opensource e-commerce for handle 5 million prducts import daily?
  • $_SERVER['HTTP_X_REQUESTED_WITH'] seemingly not available on PHP 5.1.6
  • radio value lost by $_post array
  • Tool to add code highlighting and export to HTML
  • youtube video downloaded successfully on local, but on server(online) only 0 byte flv is downloading
  • Populating a Dropdown list in PHP dynamically
  • Why is turning magic_quotes_gpc on considered a bad practice?
  • Replace html text in javascript include
  • OOP Design - Where/When do you Validate properties?
  • RSA Encrypt in PHP to decrypt in .NET
  • Encrypting with Perl CBC and decrypting with PHP mcrypt
  • Code equivalence between Javascript and PHP
  • How to track DHL in our site from DHL site , by PHP
  • php resize image
  • How to use ^/$ if it's already used as a delimiter for regex in PHP?
  • Nobody owner (99 99) in FTP caused by php functions?
  • Php deployment to remote server using FTP from SVN after each commit
  • PHP: upload image max 150x150
  • How to implement Gmail OAuth API to send email (especially via SMTP)?
  • PHP comparion doesnt work..why?
  • Curl redirect,, not working?
  • SCORM lib for php
  • After form validation, how do you redirect to a new url w/ PHP
  • A solid nickname regexp
  • SVN checkout browser
  • Redirecting a large number of URLs with htaccess or php header
  • mail sent with php's mail() has blank From field
  • PHP intersection between array and object
  • Cannot get new product attribute in grid display
  • How do you make a count that counts the number of page-views? (PHP)
  • Reading data from a MySQL database into a HTML Table?
  • How to test PHP in MySQL Strict
  • Using a database class in my user class
  • C++ equivalent of PHP's pack()
  • splitting strings in php
  • Strange bug with PHP on Windows 7
  • PHP array question
  • How to get the age from a birthdate using PHP & MySQL?
  • Setting post tags in wordpress via XMLRPC API when submitting a post?
  • Generating random thumbnails with PHP+FFMPEG
  • what are the difference between for loop & for each loop in php
  • PHP FTP Upload thousands of files
  • How to get structed result using nested set in MySQL and PHP?
  • MYSQL Select and group by date
  • Detect base64 encoding in PHP?
  • Simple PHP GET question
  • What's the meaning of the PHP token name T_PAAMAYIM_NEKUDOTAYIM?
  • jquery GET and POST confusion
  • PNGs alpha transparancy in AS3 - Unknown file-type
  • how to use htaccess redirectmatch with query_string?
  • Creating a numerical order index on a MySQL table
  • mobile browsers' can't login to my site
  • Split PDF documents into separate pages using PHP (or possibly perl)
  • How to retrieve the value from Select html element using JS prototype in php?
  • How to execute Imagemagick in PHP
  • How do you make a function read form a txt file and store random lines in a variable?
  • PHP: What's the best way to check equality of $_SERVER['HTTP_REFERER']?
  • best way to escape and create a slug
  • Searching for a complex and well-designed PHP OOP application to learn from
  • How to calculate Content-Length for a file download within Kohana PHP?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk